users@glassfish.java.net

Re: EntityManagerFactory vs. EntityManager

From: Shreedhar Ganapathy <Shreedhar.Ganapathy_at_Sun.COM>
Date: Mon, 12 Feb 2007 21:49:33 -0800

Hi Jason
Could you refer to the following from the Blueprints team for a solution:
https://blueprints.dev.java.net/bpcatalog/ee5/persistence/ejbfacade.html

in particular
https://blueprints.dev.java.net/bpcatalog/ee5/persistence/ejbfacade.html#client-caching

and
https://blueprints.dev.java.net/bpcatalog/ee5/persistence/ejbfacade.html#using_jsf


you can also ask further questions on this forum as the team has
experience with such issues:
http://forum.java.sun.com/thread.jspa?threadID=5133945&messageID=9495023#9495023


hth,
Shreedhar

Jason Lee wrote:
> Since we migrated our environment to a full Java EE stack (versus the
> JSF on Tomcat environment we were using), we've been injecting an
> EntityManagerFactory into our JSF managed beans, on the advice the
> EntityManager is not thread-safe. We have started, however, to use
> more and Session Beans (stateful and stateless) to deploy our service
> (and DAO) layers, as we've had the need to expose some of the business
> logic in an app to external process, for example. Our "stack" then,
> is now basically JSF managed bean/backing bean -> State{ful|ess}
> Session Bean service layer -> State{ful|less} DAO layer, which, this
> morning, brought up these questions:
>
> * Do we still need to inject an EMF into our DAO EJB?
> * Does that depend on the statefulness of the bean?
> * Is there a best practice with regard to the statefulness of a DAO
> Session Bean?
>
> I ran into some issues in handling an entity bean fetched from on EM
> instance and trying to remove it with another EM instance, so I'm
> wondering if I can simplify things a bit by injecting an EM (or
> creating the EM from the EMF in a @PostConstruct), or if I just need
> to make the API calls to reattach the instance.
>
> -----
> Jason Lee, SCJP
> Programmer/Analyst
> http://www.iec-okc.com <http://www.iec-okc.com/>
>