Hibernate Architecture

Hibernate a popular orm framework was created by Gavin King in 2001 as an alternate to using EJB2 style entity beans. Hibernate architecture is layered and an Object-Relational Mapping solution for Java environments. Object-Relational mapping refers to the technique of mapping data from an object model representation to a relational data model representation. It is distributed under the GNU Lesser General Public License and free to use.

Hibernate Architecture:-

The above diagram depicts a comprehensive Hibernate architecture. The Hibernate architecture abstracts application away from the underlying JDBC/JTA APIs and allows Hibernate to manage the details.

Here we will see some definitions of the objects shown in the hibernate architecture diagrams:-

SessionFactory (org.hibernate.SessionFactory)
Instances of SessionFactory are thread-safe and typically shared throughout an application. It is immutable cache of compiled mappings for a single database. Session factory objects are to be implemented using the singleton design pattern. It is a factory for Session and a client of ConnectionProvider, it can hold an optional (second level) cache of data that is reusable between transactions at a process or cluster level.

Session (org.hibernate.Session)
Session is a single threaded, short lived object representing a conversation between the application and the persistent store. Session wraps a JDBC connection and is a factory for Transaction. It holds a mandatory first level cache of persistent objects that are used when navigating the object graph or looking up objects by identifier.

Persistent objects and collections
These are short lived, single threaded objects containing persistent state and business function. Persistent objects can be ordinary JavaBeans/POJOs. They are associated with exactly one Session. Once the Session is closed, they will be detached and free to use in any application layer.

Transient and detached objects and collections
Transient and detached objects are Instances of persistent classes those are not currently associated with a Session. They may have been instantiated by the application and not yet persisted, or they may have been instantiated by a closedSession.

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

ConnectionProvider (org.hibernate.connection.ConnectionProvider)
CoonectionProvider is a factory for JDBC connections and pool also. It abstracts the application from underlying Datasource or DriverManager. CoonectionProvider is not exposed to application, but it can be extended and/or implemented by the developer.

TransactionFactory (org.hibernate.TransactionFactory)
TransactionFactory is a factory for Transaction instances. It is optional and not exposed to the application, but it can be extended and/or implemented by the developer.

Hibernate provides a range of optional extension interfaces you can implement to customize the behavior of your persistence layer.

Leave a Comment