Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Hibernate with multiple Databases/SessionFactory.

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 713
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: