What is the purpose of the Configuration class in Hibernate?

The Configuration class is Hibernate's entry point for bootstrapping the framework — it reads settings and entity mapping information and uses them to build a SessionFactory.

Key Points: • Traditionally reads properties and mappings from hibernate.cfg.xml, though modern setups (especially with Spring Boot) often configure it programmatically or via properties files instead. • Lets you register entity mapping classes or XML mapping files before building the SessionFactory. • Holds connection settings such as JDBC URL, driver, dialect, and credentials used to talk to a specific database. • Configuration.buildSessionFactory() is the call that finalizes settings and produces the SessionFactory used for the rest of the application's lifetime. • Since it's only used at startup, it isn't part of the per-request persistence flow — Session and Transaction handle that.

Example: A standalone (non-Spring) Hibernate application typically does new Configuration().configure().addAnnotatedClass(Employee.class).buildSessionFactory() once at startup to wire everything together before opening any sessions.

Code Example:

SessionFactory sessionFactory = new Configuration()
        .configure("hibernate.cfg.xml")
        .addAnnotatedClass(Employee.class)
        .buildSessionFactory();

Interview Tip: A concise interview answer is:

"The Configuration class bootstraps Hibernate — it loads connection and mapping settings, typically from hibernate.cfg.xml, registers entity classes, and its buildSessionFactory() call produces the SessionFactory the rest of the application uses to open sessions."