Chapter 2. Architecture
Figure 2.1. High Level view of the Hibernate Architecture
Figure 2.2. The Lite Architecture
- SessionFactory (
- A threadsafe (immutable) cache of compiled mappings for a single database. A factory for
Sessionand a client of
ConnectionProvider. Might hold an optional (second-level) cache of data that is reusable between transactions, at a process- or cluster-level.
- Session (
- A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps a JDBC connection. Factory for
Transaction. Holds a mandatory (first-level) cache of persistent objects, 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 might be ordinary JavaBeans/POJOs, the only special thing about them is that they are currently associated with (exactly one)
Session. As soon as the
Sessionis 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
Session. They may have been instantiated by the application and not (yet) persisted or they may have been instantiated by a closed
- Transaction (
- (Optional) A single-threaded, short-lived object used by the application to specify atomic units of work. Abstracts application from underlying JDBC, JTA or CORBA transaction. A
Sessionmight span several
Transactions in some cases. However, transaction demarcation, either using the underlying API or
Transaction, is never optional!
- ConnectionProvider (
- (Optional) A factory for (and pool of) JDBC connections. Abstracts application from underlying
DriverManager. Not exposed to application, but can be extended/implemented by the developer.
- TransactionFactory (
- (Optional) A factory for
Transactioninstances. Not exposed to the application, but can be extended/implemented by the developer.
- Extension Interfaces
- Hibernate offers many optional extension interfaces you can implement to customize the behavior of your persistence layer. See the API documentation for details.
ConnectionProviderAPIs to talk to JTA or JDBC directly.