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.
  • Session holds a mandatory (first-level) cache of saved java objects in database.
  • Session wraps JDBC connection for Transaction.

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.
  • Transaction is associated with session.


  • Query is used to create manual queries.


  • Criteria is used to apply conditions on the result set.