Multiple choice technology databases

How to create SessionFactory instance, which one is correct in the below.

  1. SessionFactory sessionFactory = new Configuration().configure();

  2. SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

  3. SessionFactory sessionFactory = new Configuration().configure().sessionFactory();

  4. SessionFactory sessionFactory = new Configuration().buildSession();

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The correct Hibernate API to create a SessionFactory is: new Configuration().configure().buildSessionFactory(). The configure() method reads hibernate.cfg.xml, and buildSessionFactory() constructs the SessionFactory. Option A is incomplete (no buildSessionFactory), Option C has a wrong method name, and Option D is incorrect.