Wednesday, 20 April 2016

How to use multiple datasources in a common hibernate application ?


If you have two datasources, you' ll need to configure Hibernate to create multiple SessionFactory objects - one for each datasource.

You can use more than one configuration files to make multiple SessionFactory objects.

For example
SessionFactory oracleSessionFactory = 
  new Configuration().configure("/com/oracle.cfg.xml")
  .setProperties(Environment.getProperties()).buildSessionFactory();

SessionFactory db2SessionFactory = 
  new Configuration().configure("/com/db2.cfg.xml")
  .setProperties(Environment.getProperties()).buildSessionFactory();

No comments:

Post a Comment

Note: only a member of this blog may post a comment.