If I understand you correct, this would be my code for your purpose.
In all my cases, the following partworks fine for me.
//the new object
Object1 o1 = new Object1();
//old object which has a relation to the new one
Object2 o2 = em.find(Object2_Id);
//add old object to the collection of new one
o1.addToObject2Collection(o2);
//persist the new one
em.persists(o1);
//be sure we have an object with an right id (database choose it)
em.flush(o1);
//o2 needs also the information of the new relation
o2.addToObject1Collection(o1);
//sometimes this isn't enough, so I need
em.merge(o2);
--
[Message sent by forum member 'theigel69']
View Post: http://forums.java.net/node/883181