Our app.ear will be used by more than one database (so, there are more than one persistence unit).
So, we have a MAIN stateful session bean which receipts queries from clients to execute some procedures.
The procedures are stored in others stateless session beans or simple java classes.
We have recorded all the persistence units in the JNDI and we pass the name of the one to use to the MAIN stateful session bean which is the remote access for the clients. No problem to access to the database through the entitymanager directly from the MAIN stateful session bean :
InitialContext jndiContext = new InitialContext();
em = (EntityManager) jndiContext.lookup("java:/"+persistenceUnitName);
How can we know in the stateless session beans or in the simple java classes the persistence unit to use without propagating the name of the persistence unit to use to all the methods ?
=> A kind of a "context" for each MAIN stateful session bean instances which will be accessible for all beans and classes called from the instances.
But how to implement it ?