ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Kalmykov" <akalmy...@openwaygroup.com>
Subject RE: insert/update objects graph
Date Wed, 20 Feb 2008 16:38:01 GMT

Thanks, that is what I would like to know. I'm just curious why <select>
is able to handle object graphs, but insert/update - no?

Best regards, Alexey Kalmykov
OpenWay


-----Original Message-----
From: Larry Meadors [mailto:larry.meadors@gmail.com] 
Sent: Wednesday, February 20, 2008 7:35 PM
To: user-java@ibatis.apache.org
Subject: Re: insert/update objects graph

If I understand your question correctly, you want to take (for
example) an Order object with a list of OrderLine objects and insert
them by just saying this:

  sqlMap.insert("order.insert", myOrder);

If so, then no, this is not a part of iBATIS.

While that is a common ORM feature, iBATIS is not an ORM, it is a SQL
mapper - it maps objects to/from SQL, not objects to/from database
tables.

That said, doing what you are asking is still pretty simple - here's a
(non-transactional) example:

public insertOrder(Order order){
  // this assumes that the "order.insert" includes a selectKey element
  sqlMap.insert("order.insert", order);
  for(OrderLine ol:order.getOrderLines()){
    ol.setOrderId(order.getOrderId());
    sqlMap.insert("orderline.insert", ol);
  }
}

If you are using Spring, you add a transaction annotation, and
ba-da-bing. Done.

For 4 lines of code, you have this instead:

  myOrderDao.insertOrder(myOrder);

Larry


On Feb 20, 2008 9:01 AM, Alexey Kalmykov <akalmykov@openwaygroup.com>
wrote:
> I am trying to evaluate iBATIS as an ORM solution for my project. I
really
> like the overall idea behind iBATIS and its approach to ORM. I have a
> question about insert and update operations. I've been successfully
loading
> graph of objects using resultMaps. But as far as I understand, I am
unable
> to insert/update a graph of user-defined objects *using only* iBATIS
> mapping. Am I right? If yes, was it an original intention not to
implement
> such feature or just there are some difficulties in iBATIS design that
> prevents from doing it?
>
>
>
> Actually, I hope that I am wrong and somehow I can insert/update a
graph of
> objects only using iBATIS mapping :)
>
> Thank you in advance.
>
>

Mime
View raw message