users@glassfish.java.net

Singleton EJB with persistence context

From: Olivier Chorier <lapsus63_at_gmail.com>
Date: Wed, 14 Dec 2011 20:46:37 +0100

Hi community,

I recently wrote an Singleton EJB and I noticed some difficulties to manage
my entities :
- The client calls a method which gets an entity from database and stores
it as private attribute (EJB attribute).
- Something is returned to the client, and then it calls another method
from the same EJB.
- The singleton didn't forget its attribute, but when trying to force
reload from database, it is said that it is not managed by the persistence
context ; even if calling merge() juste before the reload().

This error occurs when using injection with @PersistenceContext to the
EntityManager. But it doesn't occur when using the factory
(EntityManagerFactory if I remember).

Is it a bug of Glassfish, or a normal behaviour ? FYI, we are still in
3.0.1.

Thanks for any kind of explaination.
Olivier.