Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]hibernate-entitymanager-3.1beta5[b]
I have a situation where I have a group of entity beans that can be assigned to multiple database instances. I would like to assign what database instance the user is using at runtime.
I've looked at the EnteyManager and Entity Factory stuff and I see no way to override any of the properties such as hibernate.default_catalog at runtime. This would fix my problem.
I also see no way of putting more than one entity manager in the same persistence.xml file. If I could do this I could load my entity manager at runtime using jndi.
The final, and least elegant solution I can think of (and I'm not sure will work) is I could put all my entity beans in a .ejb3 file and include a .par for each entity manager (no classes just persistence.xml). Then I can do the jndi lookup at runtime and get the user connected to the correct database.
Code:
Mystuff.ear
{
-> my beans.ejb
-> dbinstance1.par
-> META-INF\persistence.xml
-> dbinstance2.par
-> META-INF\persistence.xml
-> dbinstance3.par
-> META-INF\persistence.xml
}
public EntityManager getEntityManager(String managerName) throws javax.naming.NamingException
{
EntityManager entityManager;
InitialContext jndi = new InitialContext();
try
{
entityManager = (EntityManager) jndi.lookup("java:/EntityManagers/" + managerName);
}
finally
{
jndi.close();
}
return entityManager;
}
Is there an easier solution to my problem than my last proposal? Is there a way to override entity manager properties during session creation or something like that? Is there a way to point multiple entity managers to the same beans without having several .pars?
Thanks!