Friday, December 9, 2016

Multiple configuration files

Hibernate is designed to be used with a large set of databases. The details of those databases are configured in an XML file called hibernate.cfg.xml.

If we wish to use multiple databases in our application then we have to maintain separate configuration files.


Example: Application uses Oracle and Derby database.

Here we have to maintain 2 configuration files, lets say we name it oracleconfig.cfg.xml and derbyconfig.cfg.xml.

To access them we need to create separate session Factories ->

1) SessionFactory sessionFactory1 = new  Configuration().configure("oracleconfig.cfg.xml").buildSessionFactory();

2) SessionFactory sessionFactory2 = new Configuration().configure("derbyconfig.cfg.xml").buildSessionFactory();

No comments:

Post a Comment

Home