Hibernate with multiple databases/session factory :
To use Hibernate to support many databases, We have to follow following steps.
1 - We have to create multiple SessionFactory/cfg.xml files for each Database we want to use/connect.
2 - At time of getting SessionFactory from Configuration use required SessionFactory/cfg.xml file to get SessionFactory.
Sample code:
Configuration configuration = new Configuration().configure("<complete path to your cfg.xml file>");
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
0 Comment(s)