Class SessionFactoryManagerImpl

java.lang.Object
ch.tocco.nice2.persist.core.impl.hibernate.session.SessionFactoryManagerImpl
All Implemented Interfaces:
ThreadHandlerListener, SessionFactoryManager

@Component public class SessionFactoryManagerImpl extends Object implements SessionFactoryManager, ThreadHandlerListener
This class manages the Session lifecycle for both the old (ContextManagerAdapter) and new (PersistenceServiceImpl) persistence API. This makes it possible to use both APIs together. This class contains the 'implicit' session in a ThreadLocal. The implicit session is created automatically when the persistence API is accessed for the first time in a thread (unless another session is opened explicitly before that). At the end of each request, the implicit session is closed and removed using a ThreadHandlerListener. Sessions created by this class are always bound to the current thread. Also a SessionEventListener is added which detaches the new session from the thread and re-attached the previous session (if present) when the new session is closed.