users@glassfish.java.net

Re: RE: Re: Surprising JPA (Toplink) Behaviour (glassfish v1 UR1)

From: <glassfish_at_javadesktop.org>
Date: Fri, 16 Mar 2007 13:44:32 PST

I agree that I need to pick one or the other (container managed EMFs versus application-managed), and I'm choosing container-managed.

I was able to perform a simple experiment. I took a simple servlet in my system called "Startup". It exists only for the sake if its init() method -- I wanted to load some configuration and needed a startup event and that's the best thing I could think of.

I figured this would be a perfect place to put my @PersistenceUnit annotation, and in the body of the init() method I set the emf into a static member of the POJO that formerly used application-managed EMFs.

After testing this, however, I'm still observing the stale-data problem (where jax-ws services are not showing data entered into the JSF pages). So apparently, even though both regions of code are now using "container managed" EMFs, they're not actually getting the same EMF. To test this theory, I logged the hashcode of each EMF and they are, indeed different.

XMLFileGenerator: receiving EntityManagerFactory, hash=1848253
RestaurantMenuItemsController: emf=12769563

Any idea what gyrations I can go through to make sure glassfish hands me the same EMF in my JSF managed beans as I'm getting in my servlet?
[Message sent by forum member 'pohl' (pohl)]

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