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