Hibernate Arhitecture

Hibernate Arhitecture is a layered architecture. Hibernate can be implemented in an application in two ways:

1) Minimal Architecture where application manages JDBC connections and transaction by itself and provide the same to Hibernate.

2) Comprehansive Architecture where hibernate manages everything realated to DB.

hibernate-architecture

Core component of Hibernate:

1) SessionFactory (org.hibernate.SessionFactory): It is an object which is immutable and thread safe cache of compiled mappings for a single database. It holds second level cache which is optional. It provides factory method to get instance of session object. It is a heavy weight object usually created on application start up.

2) Session (org.hibernate.Session): It is an object which is a single-threaded and short-lived representing a conversation between the application and the persistent store. It holds first level cache. It is used to get connection with database. It is light weight and intantiated each time a interaction is needed with database.

3) Persistent objects: Persistent object is short-lived, single threaded objects containing persistent state and business function. It can be as simple as ordinalry JavaBeans. They are associated with exactly one org.hibernate.Session.

4) Transient Objects: Transient objects are persistent classes instances that are not currently associated with a org.hibernate.Session.

5) Transaction (org.hibernate.Transaction): Transaction is a single-threaded, short-lived object used by the application to specify atomic units of work. It abstracts the application from the underlying JDBC, JTA or CORBA transaction. A org.hibernate.Session might span several org.hibernate.Transactions. It is optional.

6) ConnectionProvider (org.hibernate.connection.ConnectionProvider): ConnectionProvider is a factory for JDBC connections. It provides abstraction between the application and underlying javax.sql.DataSource or java.sql.DriverManager.It is optional.

7) TransactionFactory (org.hibernate.TransactionFactory): TransactionFactory is a factory for org.hibernate.Transaction instances. It is also optional.