ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <larry.mead...@gmail.com>
Subject Re: insert/update objects graph
Date Wed, 20 Feb 2008 16:34:30 GMT
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