4. Hibernate Architecture


Hibernate Architecture

Architecture

The diagram below provides a high-level view of the Hibernate architecture:

Hibernate is flexible and supports several different approaches. We will, however, show the two extremes:-

  1. Minimal Architecture
  2. Comprehensive Architecture
  1. Minimal Architecture

    • The "minimal" architecture has the application provide its own JDBC connections and manage its own transactions. This approach uses a minimal subset of Hibernate's APIs:
  2. Comprehensive Architecture

    • The "comprehensive" architecture abstracts the application away from the underlying JDBC/JTA APIs and allows Hibernate to manage the details.

Here are some definitions of the objects depicted in the diagrams:
  • SessionFactory (org.hibernate.SessionFactory)
    • Configuration object is used to create a SessionFactory object which in turn configures Hibernate for the application using the supplied configuration file and allows for a Session object to be instantiated. The SessionFactory is a thread safe object and used by all the threads of an application.
    • The SessionFactory is a heavyweight object; it is usually created during application start up and kept for later use. You would need one SessionFactory object per database using a separate configuration file. So, if you are using multiple databases, then you would have to create multiple SessionFactory objects.
  • Session (org.hibernate.Session)
    • A single-threaded, short-lived object representing a conversation between the application and the persistent store.
    • It wraps a JDBC connection and is a factory for Transaction.
    • Session 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
    • Short-lived, single threaded objects containing persistent state and business function.
    • These 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 (for example, directly as data transfer objects to and from presentation).
  • Transient and detached objects and collections
    • Instances of persistent classes that 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 closed Session.
  • Transaction (org.hibernate.Transaction)
    • (Optional) 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.
    • This is an optional object and Hibernate applications may choose not to use this interface, instead managing transactions in their own application code.
  • ConnectionProvider (org.hibernate.connection.ConnectionProvider)
    • (Optional) A factory for, and pool of, JDBC connections.
    • It abstracts the application from underlying Datasource or DriverManager.
    • It is not exposed to application, but it can be extended and/or implemented by the developer.
  • TransactionFactory (org.hibernate.TransactionFactory)
    • (Optional) A factory for Transaction instances.
    • It is not exposed to the application, but it can be extended and/or implemented by the developer.
  • TransactionFactory (org.hibernate.TransactionFactory)
    • (Optional) A factory for Transaction instances.
    • It is not exposed to the application, but it can be extended and/or implemented by the developer.

No comments:

Post a Comment

Quote of the day

Popular Posts

Featured Post

Collection Framework Overview

Collection:- A collection (sometimes called a container) is simply an object that groups multiple elements into single unit. Collect...

Youtube Page

Facebook Page

Recent Posts

About

I am Shivaji Chandra and I'm a Computer Science Engineer. I love to write poems, jokes and quotes. click here →