Top Description Methods
org.hibernate.engine.spi

public Interface SharedSessionContractImplementor

extends SharedSessionContract, JdbcSessionOwner, Options, LobCreationContext, WrapperOptions, QueryProducerImplementor
Known Direct Subinterfaces
org.hibernate.engine.spi.SessionImplementor
Known Direct Implementers
org.hibernate.internal.AbstractSessionImpl, org.hibernate.internal.AbstractSharedSessionContract
Imports
java.io.Serializable, java.sql.Connection, java.util.Iterator, .List, .UUID, javax.persistence.FlushModeType, .TransactionRequiredException, javax.persistence.criteria.Selection, org.hibernate.CacheMode, .Criteria, .FlushMode, .HibernateException, .Interceptor, .ScrollMode, .SharedSessionContract, .Transaction, org.hibernate.cache.spi.CacheTransactionSynchronization, org.hibernate.cfg.Environment, org.hibernate.collection.spi.PersistentCollection, org.hibernate.engine.jdbc.LobCreationContext, org.hibernate.engine.jdbc.spi.JdbcCoordinator, .JdbcServices, org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification, org.hibernate.internal.util.config.ConfigurationHelper, org.hibernate.jpa.spi.HibernateEntityManagerImplementor, org.hibernate.loader.custom.CustomQuery, org.hibernate.persister.entity.EntityPersister, org.hibernate.query.spi.QueryImplementor, .QueryProducerImplementor, .ScrollableResultsImplementor, org.hibernate.resource.jdbc.spi.JdbcSessionOwner, org.hibernate.resource.transaction.spi.TransactionCoordinator, .TransactionCoordinatorBuilder.Options, org.hibernate.type.descriptor.WrapperOptions

Defines the internal contract shared between org.hibernate.Session and org.hibernate.StatelessSession as used by other parts of Hibernate (such as org.hibernate.type.Type, EntityPersister and org.hibernate.persister.collection.CollectionPersister implementors A Session, through this interface and SharedSessionContractImplementor, implements:
Authors
Gavin King, Steve Ebersole

Method Summary

Modifier and TypeMethod and Description
public Transaction

Returns:

the transaction
accessTransaction
()

Provides access to the underlying transaction or creates a new transaction if one does not already exist or is active.

public void
public String
bestGuessEntityName(Object object)

The best guess entity name for an entity not in an association

public default void
checkOpen()

Performs a check whether the Session is open, and if not:

  • marks current transaction (if one) for rollback only
  • throws an IllegalStateException (JPA defines the exception type)
public void
checkOpen(boolean markForRollbackIfClosed)

Performs a check whether the Session is open, and if not:

  • if markForRollbackIfClosed is true, marks current transaction (if one) for rollback only
  • throws an IllegalStateException (JPA defines the exception type)
public default void
checkTransactionNeededForUpdateOperation(String
the message to use for the TransactionRequiredException
exceptionMessage
)

Check if an active Transaction is necessary for the update operation to be executed.

public Connection
public <T> QueryImplementor<T>

Returns:

The typed query
createQuery
(String jpaqlString, Class<T> resultClass, Selection<X> selection, HibernateEntityManagerImplementor.QueryOptions queryOptions)

Deprecated (since 5.2) - see deprecation note on org.hibernate.jpa.spi.HibernateEntityManagerImplementor#createQuery(java.lang.String, java.lang.Class, javax.persistence.criteria.Selection, org.hibernate.jpa.spi.HibernateEntityManagerImplementor.QueryOptions)
public int
executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)

Execute a native SQL update or delete query

public int
executeUpdate(String query, QueryParameters queryParameters)

Execute a HQL update or delete query

public void
public EntityKey

Returns:

The entity key
generateEntityKey
(Serializable
The entity id
id
,
EntityPersister
The entity persister
persister
)

Hide the changing requirements of entity key creation

public CacheMode
public CacheTransactionSynchronization
getCacheTransactionSynchronization()

The current CacheTransactionContext associated with the Session.

public default Integer

Returns:

Session-level or or SessionFactory-level JDBC batch size.
getConfiguredJdbcBatchSize
()

Get the currently configured JDBC batch size either at the Session-level or SessionFactory-level.

public Serializable
getContextEntityIdentifier(Object object)

Return the identifier of the persistent object, or null if not associated with the session

public int
public EntityPersister
getEntityPersister(String
optional entity name
entityName
,
Object
the entity instance
object
)

Get the EntityPersister for any instance

public Object
getEntityUsingInterceptor(EntityKey key)

Get the entity instance associated with the given Key, calling the Interceptor if necessary

public SessionEventListenerManager
public ExceptionConverter

Returns:

the ExceptionConverter for this Session.
getExceptionConverter
()

The converter associated to a Session might be lazily initialized: only invoke this getter when there is actual need to use it.

public SessionFactoryImplementor
getFactory()

Redeclares org.hibernate.query.spi.QueryProducerImplementor.getFactory.

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
Get the creating SessionFactoryImplementor
public FlushModeType

Returns:

The FlushModeType in effect for this Session.
getFlushMode
()

Get the flush mode for this session.

public FlushMode

Returns:

The flush mode
getHibernateFlushMode
()

Redeclares org.hibernate.query.spi.QueryProducerImplementor.getHibernateFlushMode.

Get the current flush mode for this session.
public Interceptor

Returns:

The interceptor.
getInterceptor
()

Retrieves the interceptor currently in use by this event source.

public JdbcCoordinator
public JdbcServices
public LoadQueryInfluencers

Returns:

the load query influencers associated with this session; should never be null.
getLoadQueryInfluencers
()

Get the load query influencers associated with this session.

public PersistenceContext
getPersistenceContext()

Get the persistence context for this session.

public PersistenceContext

Returns:

the PersistenceContext associated to this session.
getPersistenceContextInternal
()

This is similar to getPersistenceContext(), with two main differences: a) this version performs better as it allows for inlining and probably better prediction b) see SessionImplgetPersistenceContext() : it does some checks on the current state of the Session.

public UUID

Returns:

The UUID
getSessionIdentifier
()

A UUID associated with each Session.

public String

Returns:

The tenant identifier; may be null
getTenantIdentifier
()

Redeclares org.hibernate.SharedSessionContract.getTenantIdentifier.

The multi-tenancy tenant identifier, if one.
public default long
getTimestamp()

Deprecated (since 5.3) Use getTransactionStartTimestamp() instead.
public long
getTransactionStartTimestamp()

Deprecated no longer supported, when the Second Level Cache is enabled {CacheTransactionSynchronization#getCachingTimestamp()} can be used.
A "timestamp" at or before the start of the current transaction.
public String
guessEntityName(Object entity)

The guessed entity name for an entity not in an association

public Object
immediateLoad(String entityName, Serializable id)

Load an instance immediately.

public void
initializeCollection(PersistentCollection collection, boolean writing)

Initialize the collection (if not already initialized)

public Object
instantiate(String entityName, Serializable id)

Instantiate the entity class, initializing with the given identifier

public Object
instantiate(EntityPersister persister, Serializable id)

Instantiate the entity class of an EntityPersister, initializing with the given identifier.

public Object
internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)

Load an instance without checking if it was deleted.

public boolean
public boolean

Returns:

true if the session is closed; false otherwise.
isClosed
()

Checks whether the session is closed.

public default boolean
public boolean
public default boolean

Returns:

true if the session is closed or if it's waiting for auto-close; false otherwise.
isOpenOrWaitingForAutoClose
()

Checks whether the session is open or is waiting for auto-close

public default boolean
public boolean
isTransactionInProgress()

Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?

public Iterator<E>
iterate(String query, QueryParameters queryParameters)

Execute an iterate() query

public Iterator<E>
iterateFilter(Object collection, String filter, QueryParameters queryParameters)

Iterate a filter

public List<E>
list(String query, QueryParameters queryParameters)

Execute a find() query

public List<E>
list(Criteria criteria)

Execute a criteria query

public List<E>

Returns:

The result list.
list
(NativeSQLQuerySpecification
The specification of the native SQL query to execute.
spec
,
QueryParameters
The parameters by which to perform the execution.
queryParameters
)

Execute a native SQL query, and return the results as a fully built list.

public List<E>
listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)

Execute an SQL Query

public List<E>
listFilter(Object collection, String filter, QueryParameters queryParameters)

Execute a filter

public void
markForRollbackOnly()

Marks current transaction (if one) for rollback only

public ScrollableResultsImplementor
scroll(String query, QueryParameters queryParameters)

Execute a scroll() query

public ScrollableResultsImplementor
scroll(Criteria criteria, ScrollMode scrollMode)

Execute a criteria query

public ScrollableResultsImplementor

Returns:

The resulting scrollable result.
scroll
(NativeSQLQuerySpecification
The specification of the native SQL query to execute.
spec
,
QueryParameters
The parameters by which to perform the execution.
queryParameters
)

Execute a native SQL query, and return the results as a scrollable result.

public ScrollableResultsImplementor
scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)

Execute an SQL Query

public void
setAutoClear(boolean enabled)

Enable/disable automatic cache clearing from after transaction completion (for EJB3)

public void
public default void
setEnforcingFetchGraph(boolean enforcingFetchGraph)

public void
setFlushMode(FlushMode
the new flush mode
flushMode
)

Deprecated (since 5.2) use setHibernateFlushMode(FlushMode) instead
Set the flush mode for this session.
public void
setHibernateFlushMode(FlushMode
the new flush mode
flushMode
)

Set the flush mode for this session.

public boolean
Inherited from org.hibernate.engine.jdbc.LobCreationContext:
execute
Inherited from org.hibernate.query.spi.QueryProducerImplementor:
createNamedQuerycreateNamedQuerycreateNativeQuerycreateNativeQuerycreateNativeQuerycreateQuerycreateQuerycreateSQLQuerygetNamedNativeQuerygetNamedQuerygetNamedSQLQuery
Inherited from org.hibernate.resource.jdbc.spi.JdbcSessionOwner:
afterTransactionBeginafterTransactionCompletionbeforeTransactionCompletionflushBeforeTransactionCompletiongetJdbcBatchSizegetJdbcConnectionAccessgetJdbcSessionContextgetTransactionCoordinatorstartTransactionBoundary
Inherited from org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options:
shouldAutoJoinTransaction
Inherited from org.hibernate.SharedSessionContract:
beginTransactionclosecreateCriteriacreateCriteriacreateCriteriacreateCriteriacreateQuerycreateStoredProcedureCallcreateStoredProcedureCallcreateStoredProcedureCalldoReturningWorkdoWorkgetJdbcBatchSizegetNamedProcedureCallgetNamedQuerygetTransactionisConnectedisOpensetJdbcBatchSize
Inherited from org.hibernate.type.descriptor.WrapperOptions:
getJdbcTimeZonegetLobCreatorremapSqlTypeDescriptoruseStreamForLobBinding

Method Detail

accessTransactionback to summary
public Transaction accessTransaction()

Provides access to the underlying transaction or creates a new transaction if one does not already exist or is active. This is primarily for internal or integrator use.

Returns:Transaction

the transaction

afterScrollOperationback to summary
public void afterScrollOperation()
bestGuessEntityNameback to summary
public String bestGuessEntityName(Object object)

The best guess entity name for an entity not in an association

checkOpenback to summary
public default void checkOpen()

Performs a check whether the Session is open, and if not:

  • marks current transaction (if one) for rollback only
  • throws an IllegalStateException (JPA defines the exception type)
checkOpenback to summary
public void checkOpen(boolean markForRollbackIfClosed)

Performs a check whether the Session is open, and if not:

  • if markForRollbackIfClosed is true, marks current transaction (if one) for rollback only
  • throws an IllegalStateException (JPA defines the exception type)
checkTransactionNeededForUpdateOperationback to summary
public default void checkTransactionNeededForUpdateOperation(String exceptionMessage)

Check if an active Transaction is necessary for the update operation to be executed. If an active Transaction is necessary but it is not then a TransactionRequiredException is raised.

Parameters
exceptionMessage:String

the message to use for the TransactionRequiredException

connectionback to summary
public Connection connection()
createQueryback to summary
public <T> QueryImplementor<T> createQuery(String jpaqlString, Class<T> resultClass, Selection<X> selection, HibernateEntityManagerImplementor.QueryOptions queryOptions)

Deprecated

(since 5.2) - see deprecation note on org.hibernate.jpa.spi.HibernateEntityManagerImplementor#createQuery(java.lang.String, java.lang.Class, javax.persistence.criteria.Selection, org.hibernate.jpa.spi.HibernateEntityManagerImplementor.QueryOptions)

Returns:QueryImplementor<T>

The typed query

Annotations
@Deprecated
executeNativeUpdateback to summary
public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException

Execute a native SQL update or delete query

executeUpdateback to summary
public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException

Execute a HQL update or delete query

flushback to summary
public void flush()
generateEntityKeyback to summary
public EntityKey generateEntityKey(Serializable id, EntityPersister persister)

Hide the changing requirements of entity key creation

Parameters
id:Serializable

The entity id

persister:EntityPersister

The entity persister

Returns:EntityKey

The entity key

getCacheModeback to summary
public CacheMode getCacheMode()

Redeclares org.hibernate.query.spi.QueryProducerImplementor.getCacheMode.

getCacheTransactionSynchronizationback to summary
public CacheTransactionSynchronization getCacheTransactionSynchronization()

The current CacheTransactionContext associated with the Session. This may return null when the Session is not currently part of a transaction.

getConfiguredJdbcBatchSizeback to summary
public default Integer getConfiguredJdbcBatchSize()

Get the currently configured JDBC batch size either at the Session-level or SessionFactory-level. If the Session-level JDBC batch size was not configured, return the SessionFactory-level one.

Returns:Integer

Session-level or or SessionFactory-level JDBC batch size.

Since
5.2
See Also
org.hibernate.boot.spi.SessionFactoryOptions#getJdbcBatchSize, org.hibernate.boot.SessionFactoryBuilder#applyJdbcBatchSize
getContextEntityIdentifierback to summary
public Serializable getContextEntityIdentifier(Object object)

Return the identifier of the persistent object, or null if not associated with the session

getDontFlushFromFindback to summary
public int getDontFlushFromFind()
getEntityPersisterback to summary
public EntityPersister getEntityPersister(String entityName, Object object) throws HibernateException

Get the EntityPersister for any instance

Parameters
entityName:String

optional entity name

object:Object

the entity instance

getEntityUsingInterceptorback to summary
public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException

Get the entity instance associated with the given Key, calling the Interceptor if necessary

getEventListenerManagerback to summary
public SessionEventListenerManager getEventListenerManager()
getExceptionConverterback to summary
public ExceptionConverter getExceptionConverter()

The converter associated to a Session might be lazily initialized: only invoke this getter when there is actual need to use it.

Returns:ExceptionConverter

the ExceptionConverter for this Session.

getFactoryback to summary
public SessionFactoryImplementor getFactory()

Redeclares org.hibernate.query.spi.QueryProducerImplementor.getFactory.

Deprecated

as a consequence of SessionFactoryImplementor being deprecated. See corresponding docs for further information.

Get the creating SessionFactoryImplementor

getFlushModeback to summary
public FlushModeType getFlushMode()

Get the flush mode for this session.

For users of the Hibernate native APIs, we've had to rename this method as defined by Hibernate historically because the JPA contract defines a method of the same name, but returning the JPA FlushModeType rather than Hibernate's FlushMode. For the former behavior, use getHibernateFlushMode() instead.

Returns:FlushModeType

The FlushModeType in effect for this Session.

getHibernateFlushModeback to summary
public FlushMode getHibernateFlushMode()

Redeclares org.hibernate.query.spi.QueryProducerImplementor.getHibernateFlushMode.

Get the current flush mode for this session.

Returns:FlushMode

The flush mode

getInterceptorback to summary
public Interceptor getInterceptor()

Retrieves the interceptor currently in use by this event source.

Returns:Interceptor

The interceptor.

getJdbcCoordinatorback to summary
public JdbcCoordinator getJdbcCoordinator()
getJdbcServicesback to summary
public JdbcServices getJdbcServices()
getLoadQueryInfluencersback to summary
public LoadQueryInfluencers getLoadQueryInfluencers()

Get the load query influencers associated with this session.

Returns:LoadQueryInfluencers

the load query influencers associated with this session; should never be null.

getPersistenceContextback to summary
public PersistenceContext getPersistenceContext()

Get the persistence context for this session. See also getPersistenceContextInternal() for an alternative. This method is not extremely fast: if you need to access the PersistenceContext multiple times, prefer keeping a reference to it over invoking this method multiple times.

getPersistenceContextInternalback to summary
public PersistenceContext getPersistenceContextInternal()

This is similar to getPersistenceContext(), with two main differences: a) this version performs better as it allows for inlining and probably better prediction b) see SessionImplgetPersistenceContext() : it does some checks on the current state of the Session. Choose wisely: performance is important, correctness comes first.

Returns:PersistenceContext

the PersistenceContext associated to this session.

getSessionIdentifierback to summary
public UUID getSessionIdentifier()

A UUID associated with each Session. Useful mainly for logging.

Returns:UUID

The UUID

getTenantIdentifierback to summary
public String getTenantIdentifier()

Redeclares org.hibernate.SharedSessionContract.getTenantIdentifier.

The multi-tenancy tenant identifier, if one.

Returns:String

The tenant identifier; may be null

getTimestampback to summary
public default long getTimestamp()

Deprecated

(since 5.3) Use getTransactionStartTimestamp() instead.

Annotations
@Deprecated
getTransactionStartTimestampback to summary
public long getTransactionStartTimestamp()

Deprecated

no longer supported, when the Second Level Cache is enabled {CacheTransactionSynchronization#getCachingTimestamp()} can be used.

A "timestamp" at or before the start of the current transaction.

API Note

This "timestamp" need not be related to timestamp in the Java Date/millisecond sense. It just needs to be an incrementing value. See CacheTransactionSynchronization#getCurrentTransactionStartTimestamp()

Annotations
@Deprecated
guessEntityNameback to summary
public String guessEntityName(Object entity) throws HibernateException

The guessed entity name for an entity not in an association

immediateLoadback to summary
public Object immediateLoad(String entityName, Serializable id) throws HibernateException

Load an instance immediately. This method is only called when lazily initializing a proxy. Do not return the proxy.

initializeCollectionback to summary
public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException

Initialize the collection (if not already initialized)

instantiateback to summary
public Object instantiate(String entityName, Serializable id) throws HibernateException

Instantiate the entity class, initializing with the given identifier

instantiateback to summary
public Object instantiate(EntityPersister persister, Serializable id) throws HibernateException

Instantiate the entity class of an EntityPersister, initializing with the given identifier. This is more efficient than instantiate(String, Serializable) but not always interchangeable: a single persister might be responsible for multiple types.

internalLoadback to summary
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException

Load an instance without checking if it was deleted.

When nullable is disabled this method may create a new proxy or return an existing proxy; if it does not exist, throw an exception.

When nullable is enabled, the method does not create new proxies (but might return an existing proxy); if it does not exist, return null.

When eager is enabled, the object is eagerly fetched

isAutoCloseSessionEnabledback to summary
public boolean isAutoCloseSessionEnabled()
isClosedback to summary
public boolean isClosed()

Checks whether the session is closed. Provided separately from isOpen() as this method does not attempt any JTA synchronization registration, whereas isOpen() does; which makes this one nicer to use for most internal purposes.

Returns:boolean

true if the session is closed; false otherwise.

isEnforcingFetchGraphback to summary
public default boolean isEnforcingFetchGraph()
isEventSourceback to summary
public boolean isEventSource()
isOpenOrWaitingForAutoCloseback to summary
public default boolean isOpenOrWaitingForAutoClose()

Checks whether the session is open or is waiting for auto-close

Returns:boolean

true if the session is closed or if it's waiting for auto-close; false otherwise.

isQueryParametersValidationEnabledback to summary
public default boolean isQueryParametersValidationEnabled()
isTransactionInProgressback to summary
public boolean isTransactionInProgress()

Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?

iterateback to summary
public Iterator<E> iterate(String query, QueryParameters queryParameters) throws HibernateException

Execute an iterate() query

iterateFilterback to summary
public Iterator<E> iterateFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException

Iterate a filter

listback to summary
public List<E> list(String query, QueryParameters queryParameters) throws HibernateException

Execute a find() query

listback to summary
public List<E> list(Criteria criteria)

Execute a criteria query

listback to summary
public List<E> list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException

Execute a native SQL query, and return the results as a fully built list.

Parameters
spec:NativeSQLQuerySpecification

The specification of the native SQL query to execute.

queryParameters:QueryParameters

The parameters by which to perform the execution.

Returns:List<E>

The result list.

listCustomQueryback to summary
public List<E> listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException

Execute an SQL Query

listFilterback to summary
public List<E> listFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException

Execute a filter

markForRollbackOnlyback to summary
public void markForRollbackOnly()

Marks current transaction (if one) for rollback only

scrollback to summary
public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException

Execute a scroll() query

scrollback to summary
public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode)

Execute a criteria query

scrollback to summary
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters)

Execute a native SQL query, and return the results as a scrollable result.

Parameters
spec:NativeSQLQuerySpecification

The specification of the native SQL query to execute.

queryParameters:QueryParameters

The parameters by which to perform the execution.

Returns:ScrollableResultsImplementor

The resulting scrollable result.

scrollCustomQueryback to summary
public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException

Execute an SQL Query

setAutoClearback to summary
public void setAutoClear(boolean enabled)

Enable/disable automatic cache clearing from after transaction completion (for EJB3)

setCacheModeback to summary
public void setCacheMode(CacheMode cm)
setEnforcingFetchGraphback to summary
public default void setEnforcingFetchGraph(boolean enforcingFetchGraph)
setFlushModeback to summary
public void setFlushMode(FlushMode flushMode)

Deprecated

(since 5.2) use setHibernateFlushMode(FlushMode) instead

Set the flush mode for this session.

The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.

For a logically "read only" session, it is reasonable to set the session's flush mode to FlushMode#MANUAL at the start of the session (in order to achieve some extra performance).

Parameters
flushMode:FlushMode

the new flush mode

Annotations
@Deprecated
setHibernateFlushModeback to summary
public void setHibernateFlushMode(FlushMode flushMode)

Set the flush mode for this session.

The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.

For a logically "read only" session, it is reasonable to set the session's flush mode to FlushMode#MANUAL at the start of the session (in order to achieve some extra performance).

Parameters
flushMode:FlushMode

the new flush mode

shouldAutoCloseback to summary
public boolean shouldAutoClose()