Well, since in EJB3, making that POJO an EJB Stateless Session Bean Pojo will aloow you to inject the EntityManager with @PersistenceContext.
If it is only a POJO, the only way you can get it is by passing it in through a method, if it is being called by an EJB, in which the EJB gets it injected with @PersistenceContext and you pass it to the POJO. Or you can also have the POJO do a JNDI lookup manually and get it itself.
Joined: Jan 10, 2007
Thank you for your answer.
Lets assume the following scenario:
Facade - stateless session bean (transaction required) - get entity manager through Jndi
SaveItem - simple class (no ejb) - get entity manager through Jndi
Facde call to SaveItem .
How can i ensure that they will share the same entity managet and the same transaction?
Does i need i the Pojo to call to begin transaction?
The POJO will just inherit the container context from the session bean so the transaction and EntityManager and will be shared as well.
As Mark mentioned, injecting the EM into the session bean is going to be way easier than looking it up in JNDI, and since you are in the same container context you can safely pass that EM along to the POJO.