You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by daheri <er...@hotmail.com> on 2007/03/21 10:34:40 UTC

How to handle Insert and update of 1:N objects

Hi,

I've just started out with iBATIS and have not found any information on this
subject anywhere.
I have one javabean (ITEM) containing a list of other javabeans
(ALTERNATIVE). I was hoping to handle everything through a ItemDAO.

The iBATIS mapping for the selects works perfectly. Then I can create a
couple of resultmaps and use the groupBy and the beans are populated like a
charm.

But when i now try to do the exact opposite it gets a bit difficult. Is
there a way to create a insert which take the ITEM as a parameterclass and
then inserts the ITEM in the database, then iterate through the list of
ALTERNATIVE adding all those as well?

Or do I have to create a new AlternativeDAO and handle the Alternatives
seperatly?

Thanks in advance for your help.
-- 
View this message in context: http://www.nabble.com/How-to-handle-Insert-and-update-of-1%3AN-objects-tf3439472.html#a9590312
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: How to handle Insert and update of 1:N objects

Posted by Larry Meadors <lm...@apache.org>.
No, there is not a way to do that automatically, you have to insert
(or update) the parent, then iterate through the child records in code
inserting (or updating) them.

Larry


On 3/21/07, daheri <er...@hotmail.com> wrote:
> I've just started out with iBATIS and have not found any information on this
> subject anywhere.
> I have one javabean (ITEM) containing a list of other javabeans
> (ALTERNATIVE). I was hoping to handle everything through a ItemDAO.
>
> The iBATIS mapping for the selects works perfectly. Then I can create a
> couple of resultmaps and use the groupBy and the beans are populated like a
> charm.
>
> But when i now try to do the exact opposite it gets a bit difficult. Is
> there a way to create a insert which take the ITEM as a parameterclass and
> then inserts the ITEM in the database, then iterate through the list of
> ALTERNATIVE adding all those as well?
>
> Or do I have to create a new AlternativeDAO and handle the Alternatives
> seperatly?
>
> Thanks in advance for your help.
> --
> View this message in context: http://www.nabble.com/How-to-handle-Insert-and-update-of-1%3AN-objects-tf3439472.html#a9590312
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>