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
|