Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hibernate, Multi DB?

Status
Not open for further replies.

JonAustin1905

Programmer
Feb 6, 2004
21
US
I've got a prototype app running, which management are very eager to deploy..

Which is unsurprising, as it tramples on the original version.

However it's using Spring/Hibernate, and the connection object is instatiated at server initialization, based on the settings in the Hibernate properties file.

In the prototype, it connects from the DEV platform, to the DEV DB.. All's well..

However when deployed, we log in from the QA platform, to a number of QA, or Production DB's..

Does anyone know how we can go about making this dynamic?

Thanks,

~ Jon
 
You can have different SessionFactory instances, once for each database, created from different hibernate configuration file set with different database URL.

e.g.

Code:
SessionFactory sessionFactoryDB1 = new Configuration().configure("db1.cfg.xml").buildSessionFactory();

SessionFactory sessionFactoryDB2 = new Configuration().configure("db2.cfg.xml").buildSessionFactory();

SessionFactory sessionFactoryDB3 = new Configuration().configure("db3.cfg.xml").buildSessionFactory();

// etc.  use appropiate session factory for desire database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top