Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Using Hibernate to connect to more than one db

  Asked By: Aditi    Date: Feb 19    Category: Java    Views: 1965
  

We want to use Hibernate and try to configure it to connect to more than one database at the same time. Is it possible to configure Hibernate for this issue?
Or we should open one Hibernate session for each database.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Coleman Smith     Answered On: Feb 19

For each table, you may add two more attributes named "entity" and "schema". entity is defined to prevent collision between entities with the same name in different schemas, and schema is your real database  namespace. Then you use the entity name in your HQL. We have tested this method with MySQL. On saturday, when I am back at work, I will be able to send you hbm.xml files if you need more details, but I think searching those two attributes will guide you to the answer.

 
Answer #2    Answered By: Benny Torres     Answered On: Feb 19

As I know ,you need a sessionFactory for every one.
But If th DB is Oracle there is another way : you can let scheamas see each other.

 
Answer #3    Answered By: Ulfah Hashmi     Answered On: Feb 19

Take al look at our configuration files attached to this email.
By the way, these are our hibernate  queries:


List all = session.createQuery("from MBM.User").list();
List all = session.createQuery("from IB.User").list();

 
Answer #4    Answered By: Adaulfo Fischer     Answered On: Feb 19

One of my friends a solution mentioned at:
sandbox.sourcelabs.com/.../virtualization.html

It uses multi-datasource before getting hibernate  Session

 
Didn't find what you were looking for? Find more on Using Hibernate to connect to more than one db Or get search suggestion and latest updates.




Tagged: