ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Saluja <rahul.sal...@vnl.in>
Subject RE: Need help on Inserting child Object .
Date Mon, 09 Feb 2009 11:21:14 GMT
Hi Ingmar,

Thanks for replying and being so patient in answering my queries,

Well I could not understand what you actually mean to say by this

" This works only, if there are no depedencies to the child table and if you don't have to
log the changes "

Do you mean to say that I should not run update query on my child table, well all I need to
do is insert the data of parent object and child object in corresponding tables but no update
, as all this data will be used just for reporting.

I could not understand what you were pointing to while stating ---> "if there are no dependencies
to the child table"

Looking forward to your response.

Rahul Saluja

-----Original Message-----
From: Ingmar Lötzsch [mailto:iloetzsch@asci-systemhaus.de]
Sent: Monday, February 09, 2009 4:30 PM
To: user-java@ibatis.apache.org
Subject: Re: Need help on Inserting child Object .

Hello Rahul,

> I have gone through the link you gave me here is what is been given there
> <insert id="InsertOrganization" parameterClass="Organization" resultClass="int">
>         <selectKey property="Id" type="post" resultClass="int">
>                 SELECT cast(last_value as int) AS value
>                 FROM organizations_org_id_seq
>         </selectKey>
>         INSERT INTO Organizations
>                 (Org_Code, Org_Name)
>         VALUES
>                 (#Code#, #Name#)
> </insert>
> What I can understand from above lines that I can select the last generated key my question
is how I can use this last generated key as a foreign key to another table (that table is
referring to nothing but child object of Organization class).
> So how will this work that while inserting my
> For the parent object say data I will call MSCPerfCntrMscMMSTblImpl and insert into MSCPerfCntrMscMMSTbl
but my MSCPerfCntrMscMMSTblImpl object contains a child object which contains data for another
table so at my application level do I have to code in following manner using Batch process?

If your database is normalized, yes. As far as I know. If you have an
array of an userdefined type MSCPerfCntrMscMMSTbl, you have to act

> public void saveOrder(SqlMapClient sqlMapClient, Order order)
> throws SQLException {
> sqlMapClient.startTransaction();
> try {
> if (null == order.getOrderId()) {
> sqlMapClient.insert("Order.insert", order);
> } else {
> sqlMapClient.update("Order.update", order);
> }
> sqlMapClient.startBatch();
> sqlMapClient.delete("Order.deleteDetails", order);

This works only, if there are no depedencies to the child table and if
you don't have to log the changes.

> for (int i=0;i<order.getOrderItems().size();i++) {
> OrderItem oi = (OrderItem) order.getOrderItems().get(i);
> oi.setOrderId(order.getOrderId());
> sqlMapClient.insert("OrderItem.insert", oi);
> }
> sqlMapClient.executeBatch();
> sqlMapClient.commitTransaction();
> } finally {
> sqlMapClient.endTransaction();
> }
> }

The information contained in this e-mail is private & confidential and may also be legally
privileged. If you are not the intended recipient, please notify us, preferably by e-mail,
and do not read, copy or disclose the contents of this message to anyone.

View raw message