Authors: Konstantin Pribluda
Deprecation warning
Classes and methods described here are deprecated for various reasons. Mostly because there are better ways to do this. Better way to deal with hibernate support is described here.
Overview
Hibernate integration kit provides components for hibernate session management and configuration.
NanoContainer-Hibernate integrates Hibernate with the PicoContainer world. It is distributed separately to NanoContainer itself as an 'extra' in nanocontainer-hibernate-N.n.jar
Session Provider (deprecated , because intrusive)
Session provider is responsible for session lifecycle management. Its puprose is to decouple actual data access code from hibernate session lifecycle and allow to reuse of hibernate session between several components. Major drawback of this approach is that it is intrusive, and requires explicit dependency to nanocontainer classes. This is kind of uncool, and not very picoish.
LifecycleSessionProvider ( also deprecated from above reason)
At the moment there is only one concrete implementation - LifecycleSessionProvider .
This implementation performs lazy session creation and closes it on end of container lifecycle. IIt also starts hibernate transaction explicitely on session creation, and commits it before session close. In case of any errors, session shall be reset and transaction rolled back - as recomendet by hibernate folks. This session provider can be used in web application with request lifecycle.
It has only one dependency of type SessionFactoryProvider
Typical usage patterm
Typical usage pattern is to obtain hibernate session from a sessionprovider, perform necessary data manipulation.
Session can be flushed, but this is not necessary - session provider will do it on end of lifecycle automatically.
Of course you shall watch for occasional hibernate exception ( which means that session is not more usable ) and
discard it in this case by calling reset().
Session injection
These classes are non-intrusive, but not very configuration friendly. It'd difficult to set up stacks of component adapters in code, and even more difficult in scripted configuration. It needs really ugly XML code and ugly hacks in container builder. So, it's better deprecated.
SessionComponentAdapter
Hibernate session is interface, and must be obtained from session factory. SessionComponentAdapter
is a wrapper encapsulating this logic. Just register it into container, and fresh hiberante session will be injected in your constructor. This component adapter will try to obtain dependency to hibernate session factory.
SessionFailoverComponentAdapter
Hibernate session may become stale and shall be disposed on every hibernate exception arising from it.
SessionFailoverComponentAdapter
is delegating component adapter ( delegates to SessionComponentAdapter ) and wraps session by proxy
to watch for any errors, or closing. In case of error, session will be cleared,closed, and disposed of.
In case of closing it will be disposed. New session will be obtained transparently for components.
SessionFactoryComponentAdapter
Hibernate session factory is also interface, and can not be constructed. SessionFactoryComponentAdapter
encapsulates this logic. It depends on hibernate configuration object.
