-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Can I assign the same entity beans to multiple Databases?
PostPosted: Thu Dec 15, 2005 11:06 am 
Newbie

Joined: Wed Dec 07, 2005 2:01 pm
Posts: 8
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!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 7:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can use Ejb3Configuration to do so, but the DI will not work.
Seleral par and 1 jar can work too

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 11:38 am 
Newbie

Joined: Wed Dec 07, 2005 2:01 pm
Posts: 8
Thanks, emmanuel. I played with the Ejb3Configuration, but I couldn't get it to do what I wanted. The multiple par thing worked so I'll go with that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.