Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Additional relationships can be explicitly declared using Hibernate annotations.

The Hibernate Session (Cache) and the Context Object

Hibernate will intelligently cache objects in the current Hibernate Session, allowing for optimized performance.  The hibernate cache is accessible from the DSpace Context objectHibernate Session is managed by the HibernateDBConnection object (This object is perhaps unfortunately named as it manages the process of obtaining a database connection from Hibernate, via a Session. It does not represent a single database connection)

The DSpace Context object has methods (like uncacheEntity() and reloadEntity()) which can manage this Hibernate Session Cache (via HibernateDBConnection).

Some care is needed to properly utilize the hibernate cachethe Hibernate cache.  Objects are loaded into the Session cache on access. Objects are not removed from the cache until one of the following occurs:

  • The Hibernate Session's Transaction is committed (e.g. via a call to Context.commit() or Context.complete())
  • The Hibernate Session's Transaction is rolled back (e.g. via a call to Context.abort())
  • The object is specifically "evicted" (i.e. uncached) from the Hibernate Session (e.g. via a call to Context.uncacheEntity())

Be aware, once an object is removed from the Session cache, it will need to be reloaded from the database before it can be used again!  This can be achieved via Context.reloadEntity().

Context Configurations

The DSpace Context Object can be constructed as a read-only context or a batch context.  This mode determines how hibernate will flush changes to the database.

...