users@glassfish.java.net

Re: Caching problem with build b58c-fcs?

From: <glassfish_at_javadesktop.org>
Date: Tue, 28 Aug 2007 13:52:59 PDT

Gordon,

you are right that I confused Persistence Unit and Persistence Context. Both Session Beans are not acting within the same transaction.

When I said previously "... the EntityManagers refer to the same persistence context ...", this was because both stateless session beans share the same Persistence [b]Unit[/b], as both beans contain the following EntityManager declaration with the identical "unitName" attribute:

@javax.persistence.PersistenceContext(unitName="backoffice")
private EntityManager em;

As Marina suggested, I read "5.6 Container-managed Persistence Contexts" in the JPA spec. I really do not understand it fully, but I came to the conclusion that for my application it is not a good idea to have two session beans with two entity managers, because of the observed effects. I did implement it this way purely for cosmetical reasons, to separate actions that a normal user can initiate from actions that an administrator can initiate. Both session beans operate on the same entities, and to avoid the effect of the separate caches I will merge them into one bean.

Regards
Stephan
[Message sent by forum member 'smuehlst' (smuehlst)]

http://forums.java.net/jive/thread.jspa?messageID=232980