-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: EnitityManager merge cause two inserts for collection
PostPosted: Tue Apr 19, 2011 10:20 am 
Newbie

Joined: Tue Apr 19, 2011 9:25 am
Posts: 5
I have an entity MainEntity
MainEntity has a collection of ChildEntity.

I do the following:
1. ChildEntity ch = new ChildEntity();

2. MainEntity me = getMainEntity(mainEntity ID); // this will retrieve the MainEntity from database
3. ch.setMainEntity(me);
4. me.getChildEntityCollection().add(ch);
5. EnittyManager.merge(me).

This cause 2 inserts for Child entity.

The primary key for the entity is auto generated.
The child entity is lazily loaded in Main Entity.

I also noticed that in the debug mode when I put a breakpoint before merging, and force lazily load the childEntityCollection, then only one row gets inserted.

Any help is appreciated.

Thanks,
Alpha7


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.