Thursday, March 5, 2009

Hibernate Notes - 1

Random notes on Hibernate:

Some important objects of Hibernate:
1) SessionFactory: Threadsafe/immutable cache of compiled mappings to a single database. For each database there is one SessionFactory object. It's a factory of sessions and client of ConnectionProvider. Holds optional secondary-level cache of objects.

2) Session: Single threaded, short lived object. Factory of Transactions. Wraps up JDBC Connection. Holds mandatory first-level cache of objects.

3) Transaction: Single threaded, short lived object. Represents atomic units of work. A session might span multiple Transactions.


State of Instance objects:
1) Persistent: Object is associated with a persistent context. It has a persistence identity(primary key). Hibernate guarantees that the persistent identity is equivalent to the java identity.

2) Detached: Object was once associated with persistence context, however the context is closed. Hibernate makes no guarantee about the relationship between the persistent context and java context.
3) Transient: Object is not and never has been associated with persistence context. Has no persistent identity(primary key value).