Top Description Methods
org.hibernate.context.spi

public Interface CurrentSessionContext

extends Serializable
Known Direct Implementers
org.hibernate.context.spi.AbstractCurrentSessionContext
Imports
java.io.Serializable, org.hibernate.HibernateException, .Session

Defines the contract for objects which are able to manage the lifecycle of a Session associated with a well-defined "context" or "scope", providing the concrete implementation behind the notion of the current session.

The lifecycle of the context/scope is not specified by Hibernate, and varies depending on the nature of the program. The only hard restriction is that the scope must be single-threaded. On the other hand, since state tends to build up in the first-level cache of session, sessions should typically not be associated with long-lived scopes.

The most typical example of a scope with which a current session might be associated is the HTTP request context in a web application.

An implementation of this interface must:

Every session factory has exactly one instance of this interface.

An implementation may be selected by setting the configuration property hibernate.current_session_context_class.

Author
Steve Ebersole
See Also
org.hibernate.SessionFactory#getCurrentSession(), org.hibernate.cfg.AvailableSettings#CURRENT_SESSION_CONTEXT_CLASS

Method Summary

Modifier and TypeMethod and Description
public Session

Returns:

The current session.
currentSession
()

Retrieve the current session according to the scoping defined by this implementation.

Method Detail

currentSessionback to summary
public Session currentSession() throws HibernateException

Retrieve the current session according to the scoping defined by this implementation.

Returns:Session

The current session.

Exceptions
HibernateException:
Typically indicates an issue locating or creating the current session.