Class ThreadLocalSessionContext

    • Constructor Detail

      • ThreadLocalSessionContext

        public ThreadLocalSessionContext​(SessionFactoryImplementor factory)
        Constructs a ThreadLocal
        Parameters:
        factory - The factory this context will service
    • Method Detail

      • currentSession

        public final Session currentSession()
                                     throws HibernateException
        Description copied from interface: CurrentSessionContext
        Retrieve the current session according to the scoping defined by this implementation.
        Returns:
        The current session.
        Throws:
        HibernateException - Typically indicates an issue locating or creating the current session.
      • getFactory

        protected SessionFactoryImplementor getFactory()
        Getter for property 'factory'.
        Returns:
        Value for property 'factory'.
      • buildOrObtainSession

        protected Session buildOrObtainSession()
        Strictly provided for sub-classing purposes; specifically to allow long-session support.

        This implementation always just opens a new session.

        Returns:
        the built or (re)obtained session.
      • isAutoCloseEnabled

        protected boolean isAutoCloseEnabled()
        Mainly for subclass usage. This impl always returns true.
        Returns:
        Whether the session should be closed by transaction completion.
      • isAutoFlushEnabled

        protected boolean isAutoFlushEnabled()
        Mainly for subclass usage. This impl always returns true.
        Returns:
        Whether the session should be flushed prior to transaction completion.
      • getConnectionHandlingMode

        protected PhysicalConnectionHandlingMode getConnectionHandlingMode()
        Mainly for subclass usage. This impl always returns after_transaction.
        Returns:
        The connection release mode for any built sessions.
      • bind

        public static void bind​(Session session)
        Associates the given session with the current thread of execution.
        Parameters:
        session - The session to bind.
      • unbind

        public static Session unbind​(SessionFactory factory)
        Disassociates a previously bound session from the current thread of execution.
        Parameters:
        factory - The factory for which the session should be unbound.
        Returns:
        The session which was unbound.