Step 3-Hibernate Classes and Interfaces


1- Configuration class – includes 2 things

(i)Database connection- Using either .cfg or .properties file.
(ii)mapping – connection between java classes to database tables using either .hbm files or annotations.

2-Session Interface-

  • Object of Session is created each time when any operation is required.
  •  Session objects are used to create physical connection with database.
  • Session is thread-safe, so many threads can execute it simultaneously.
  • Session holds a mandatory (first-level) cache of saved java objects in database.
  • Session wraps JDBC connection for Transaction(actual db interaction).

3-SessionFactory Interface-

  • Object of SessionFactory should be created only once per database.
  • SessionFactory is used to create session objects.

4- Transaction Interface- 

  • Transaction represents unit of work with database OR Transaction is actual interaction with database to perform operations defined on session.
  • Transaction is associated with session.


  • Query is used to create manual queries(hql/sql).


  • Criteria is used to apply conditions.