[jboss-user] [EJB 3.0] - Re: ManyToOne and ManyToMany foreign key issues

rfreden do-not-reply at jboss.com
Tue Jul 11 11:05:42 EDT 2006


For that I get: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: entity.Test2

on the line that reads: entityManager.persist(t1);

I guess that this is because the Test2 objects are being re-persisted, so I modified it to read:

Test1 t1=new Test1();
ArrayList<Test2> a=new ArrayList<Test2>();
Test2 t2=new Test2();
t2.setField(1);
entityManager.persist(t2);
a.add(t2);
t2=new Test2();
t2.setField(2);
entityManager.persist(t2);
a.add(t2);
// t1.setTest2s(a);
t1.setField(1);
entityManager.persist(t1);
t1.setTest2s(a);
entityManager.merge(t1);

the only issue being that the results are as in the initial case: no foreign keys

I failed to mention it previously, but as to my ManyToMany relationships--the join table is created, and correctly, but there are never any rows inserted, even though either side has the correct data

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957028#3957028

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957028



More information about the jboss-user mailing list