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 Need help on Inserting child Object .
Date Sun, 08 Feb 2009 11:05:48 GMT

Hello Everybody,

 I need help to understand how can I insert an object into my Db using which is having an
child object.

Say I have a class named Order which have an Child Object (an array of type OrderItem ) so
how I would write my code in java to associate these two tables
Namely Order
Class Order{

public void setOrderItemArray(OrderItem[] newArray);
public OrderItem[] getOrderItemArray();
public void setOrderItem(int index, OrderItem oi);
public OrderItem getOrderItem(int index);

and OrderItem

Class OrderItem{

Public void SetOrderItemPrice( int price);
Public int getOrderItemPrice( String OrderItemName );

Public void setOrderItemNumber(int OrderItemName);
Public int getOrderItemNumber( String ItemName);

Public void setOrderItemName(String Name);
Public String getOrderItemName(String Name);


I was Going through book Ibatis in Action and found this example under the topic inserting
or updating child object

public void saveOrder(SqlMapClient sqlMapClient, Order order)
throws SQLException {
try {
if (null == order.getOrderId()) {
sqlMapClient.insert("Order.insert", order);
} else {
sqlMapClient.update("Order.update", order);
sqlMapClient.delete("Order.deleteDetails", order);
for (int i=0;i<order.getOrderItems().size();i++) {
OrderItem oi = (OrderItem) order.getOrderItems().get(i);
sqlMapClient.insert("OrderItem.insert", oi);
} finally {

As I was going through above code I have few question why are checking it against null for
insert , shouldn't that be checking for not null

Though I can understand that It needs to be done at application level only using sql batch
update but an explicit example of the same with corresponding entries in sqlmap would help
. If somebody can put some light on this would help me in great manner.

Looking forward to your response.

Rahul Saluja
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