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. Regards Rahul Saluja -----Original Message----- From: Ingmar Lötzsch [mailto:[email protected]] Sent: Monday, February 09, 2009 4:30 PM To: [email protected] 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 different. > 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(); > } > } Ingmar 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.
