1

i have a similar issue as the guy from this post:
JPA cascade persist and references to detached entities throws PersistentObjectException. Why? (only that i have ManyToMany instead of OneToOne) and i solved it by either:
1. removing Cascade
2. using merge instead of persist
but (there is always a 'but'), if i choose the nr 2, after this operation has completed and if i look in the database everything is ok, when i perform

Bar bar = em.find(Bar.class,barId);  
List<Foo> foos = bar.getFoos(); 

i get the Bar entity without the the new Foo objects added by merge operation.
I specify that if i remove Cascade and use em.persist() everything works as expected.
Any sugestions ?

Community
  • 1
  • 1
Videanu Adrian
  • 972
  • 3
  • 16
  • 41
  • Without seeing the code it's difficult to give an answer. My guess is that you are looking for the related foos inside the transaction scope. Read this http://stackoverflow.com/a/9258520/870122 and this http://blog.xebia.com/2009/03/16/jpa-implementation-patterns-bidirectional-assocations/ – perissf Feb 23 '12 at 08:40
  • Please refer to http://stackoverflow.com/questions/13370221/jpa-hibernate-detached-entity-passed-to-persist/13500921#13500921 – Sym-Sym Oct 28 '13 at 16:13

0 Answers0