Hibernate Framework Objects

  • SessionFactory Object(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.
    • Heavy weight object hence usually created during application start up and kept for later use.
    • A thread safe (immutable) cache of compiled mappings for a single database.
    • One SessionFactory object required per database using a separate configuration file.
  • Session Object(org.hibernate.Session)
    • Used to get a Physical connection with a database.
    • Persistent objects are saved & retrieved through a Session object ONLY.
    • Lightweight & designed to be instantiated each time an interaction is needed with the database.
    • Not Thread Safe. Hence, should not be kept open for a long time (should be created & destroyed as needed)
    • A single-threaded, short-lived object representing a conversation between the application and the persistent store.
  • Transaction Object(org.hibernate.Transaction)
    • Transactions in Hibernate are handled by an underlying transaction manager and transaction (from JDBC or JTA).
    • A single-threaded, short-lived object used by the application to specify atomic units of work.
    • Abstracts application from underlying JDBC, JTA transactions.
  • Persistent objects and collections
    • Short-lived, single threaded objects containing persistent state and business function.
    • These might be ordinary JavaBeans/POJOs, the only special thing about them is that they are currently associated with (exactly one) Session.
    • Changes made to persistent objects are reflected to the database tables.
    • As soon as the Session is closed, they will be detached and free to use in any application layer(e.g. 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 org.hibernate.Session.
    • They may have been instantiated by the application and not yet persisted, or they may have been instantiated by a closed org.hibernate.Session.
  • ConnectionProvider (org.hibernate.connection. ConnectionProvider)
    • (Optional) A factory for, and pool of, JDBC connections.
    • It abstracts the application from underlying javax.sql.DataSource or java.sql.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 org.hibernate.Transaction instances.
    • It is not exposed to the application, but it can be extended and/or implemented by the developer.