[jboss-user] [JBoss Seam] - Re: JPA/Hibernate Entity: broken identity between Entity & O

Andy Gibson do-not-reply at jboss.com
Sat Dec 1 22:13:43 EST 2007


While the entities are all within the same navigation and request, you may get different entities due to entity manager flushes when queries are run.

When you execute a query, it can flush the entity manager therefore invalidating the entity manager entity cache.

For example :


  |   MyClass a = entityManager.find(MyClass.class,id);
  |   MyList = entityManager.createQuery("...").getResultList();
  |   MyClass b = entityManager.find(MyClass.class,id);
  | 

Here, I believe 'a' and  'b' would be different objects representing the same entity with the same id because the query caused a flush which invalidated the cache and caused the entity manager to create and load a new instance of the entity. 

What you could try, to diagnose the problem a bit is adding : 


  |   entityManager.save(a);
  |   entityManager.save(b);
  | 

If one of them is a stale detached object, then the entity manager will complain. 



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

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



More information about the jboss-user mailing list