Hi,
I am working in a container managed enviroment accessing interacting with entities
via stateless session beans. I am injecting the PersistenceContext in the standard JEE way
within the stateless session bean. I have made my entityManager available via JNDI.
My question is whether is legal to have methods on my entity which gain a reference to
an entityManager via a JNDI lookup. I then perform named queries.
If so, will the entityManager be the same one injected by by the stateless session bean?
The example method is
Code:
@Transient
public Address getCurrentAddress()
{
try
{
Context ctx = new InitialContext();
EntityManager em = (EntityManager) ctx.lookup(ENTITY_MANAGER_JNDI_NAME);
return (Address)em.createNamedQuery("aNamedQuery").getSingleResult();
}
catch( NamingException e )
{
throw new RuntimeException( e );
}
}