> Hello Stephan,
>
> Are you using TopLink Essentials (TLE) as the JPA
> provider? If yes, it caches
> the entities as-is at the end of the transaction, and
> when you ask for it again
> in another EM, you get not the database view, but the
> cached one. It's by design.
Yes it's TLE.
> If your case is different, feel free to file a bug.
> If it's not, your only
> solutions are to either disable cache, or refresh
> your objects calling
> em.refresh on them (don't forget to use
> cascade-refresh on the relationships).
>
I inserted an explicit em.refresh() after the existing em.fetch(), and that indeed fixes the problem!
But for my understanding, can you please elaborate what it means to "... ask for it again in another EM..."? I have two different stateless session beans that each have their own private injected EntityManager, and the EntityManagers refer to the same persistence context. Both session beans manipulate the entities A and B.
Does it mean that as a consequence it is a bad practice to have distinct session beans with their own EntityManagers referring to the same PersistenceContext, because the caches associated with the EntityManagers could interfere with each other? Does it mean that data could be lost in the worst case when one cache is flushed after the other, and changes made previously to the database are overwritten with data from the other cache?
Thanks a lot
Stephan
[Message sent by forum member 'smuehlst' (smuehlst)]
http://forums.java.net/jive/thread.jspa?messageID=232550