Interface SharedSessionContractImplementor
-
- All Superinterfaces:
AutoCloseable
,Closeable
,JavaType.CoercionContext
,JdbcSessionOwner
,LobCreationContext
,QueryProducer
,QueryProducerImplementor
,Serializable
,SharedSessionContract
,TransactionCoordinatorBuilder.Options
,WrapperOptions
- All Known Subinterfaces:
EventSource
,SessionImplementor
- All Known Implementing Classes:
AbstractDelegateSessionImplementor
,AbstractSharedSessionContract
,SessionDelegatorBaseImpl
,SessionImpl
,SharedSessionDelegatorBaseImpl
,StatelessSessionImpl
,ToOneDelegateSessionImplementor
public interface SharedSessionContractImplementor extends SharedSessionContract, JdbcSessionOwner, TransactionCoordinatorBuilder.Options, LobCreationContext, WrapperOptions, QueryProducerImplementor, JavaType.CoercionContext
Defines the internal contract shared betweenSession
andStatelessSession
as used by other parts of Hibernate, including implementors ofType
,EntityPersister
, andCollectionPersister
.The
Session
, via this interface andSharedSessionContractImplementor
, implements:-
JdbcSessionOwner
, and so the session also acts as the orchestrator of a "JDBC session", and may be used to construct aJdbcCoordinator
. -
TransactionCoordinatorBuilder.Options
, allowing the session to control the creation of theTransactionCoordinator
delegate when it is passed as an argument toTransactionCoordinatorBuilder.buildTransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner, org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options)
-
LobCreationContext
, and so the session may act as the context for JDBC LOB instance creation. -
WrapperOptions
, and so the session may influence the process of binding and extracting values to and from JDBC, which is performed by implementors ofJdbcType
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.hibernate.engine.jdbc.LobCreationContext
LobCreationContext.Callback<T>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description Transaction
accessTransaction()
Retrieves the currentTransaction
, or creates a new transaction if there is no transaction active.void
afterOperation(boolean success)
Check if there is a Hibernate or JTA transaction in progress and, if there is not, flush if necessary, making sure that the connection has been committed (if it is not in autocommit mode), and finally run the after completion processing.void
afterScrollOperation()
Called after each operation on aScrollableResults
, providing an opportunity for a stateless session to clear its temporary persistence context.default EventSource
asEventSource()
Cast this session toEventSource
if possible.default SessionImplementor
asSessionImplementor()
Cast this object toSessionImplementor
, if possible.default StatelessSession
asStatelessSession()
Cast this object toStatelessSession
, if possible.boolean
autoFlushIfRequired(Set<String> querySpaces)
detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flushdefault boolean
autoFlushIfRequired(Set<String> querySpaces, boolean skipPreFlush)
default void
autoPreFlush()
String
bestGuessEntityName(Object object)
Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session.default String
bestGuessEntityName(Object object, EntityEntry entry)
Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session.default void
checkOpen()
Check whether the session is open, and if not: mark the current transaction, if any, for rollback only, and throw anIllegalStateException
.void
checkOpen(boolean markForRollbackIfClosed)
Check whether the session is open, and if not: ifmarkForRollbackIfClosed = true
, mark the current transaction, if any, for rollback only, and throw anIllegalStateException
.default void
checkTransactionNeededForUpdateOperation(String exceptionMessage)
Check if an activeTransaction
is available before performing an update operation against the database.void
flush()
Flush this session.EntityKey
generateEntityKey(Object id, EntityPersister persister)
Instantiate anEntityKey
with the given id and for the entity represented by the givenEntityPersister
.CacheMode
getCacheMode()
Get the currentCacheMode
for this session.CacheTransactionSynchronization
getCacheTransactionSynchronization()
The currentCacheTransactionSynchronization
associated with this session.default Integer
getConfiguredJdbcBatchSize()
Get the currently configured JDBC batch size, which might have been specified at either the session or factory level.Object
getContextEntityIdentifier(Object object)
Return the identifier of the persistent object, or null if it is not associated with this session.EntityPersister
getEntityPersister(@Nullable String entityName, Object object)
Get theEntityPersister
for the given entity instance.Object
getEntityUsingInterceptor(EntityKey key)
Get the entity instance associated with the givenEntityKey
, calling theInterceptor
if necessary.SessionEventListenerManager
getEventListenerManager()
Get theSessionEventListenerManager
associated with this session.ExceptionConverter
getExceptionConverter()
Obtain anExceptionConverter
for reporting an error.SessionFactoryImplementor
getFactory()
Obtain the factory which created this session.FlushModeType
getFlushMode()
Deprecated.there's no good reason to expose this hereFlushMode
getHibernateFlushMode()
Get the currentFlushMode
for this session.Interceptor
getInterceptor()
Retrieves theInterceptor
associated with this session.JdbcCoordinator
getJdbcCoordinator()
Obtain theJdbcCoordinator
for this session.JdbcServices
getJdbcServices()
Obtain theJdbcServices
for the factory which created this session.LoadQueryInfluencers
getLoadQueryInfluencers()
Get theLoadQueryInfluencers
associated with this session.boolean
getNativeJdbcParametersIgnored()
PersistenceContext
getPersistenceContext()
Get the persistence context for this session.PersistenceContext
getPersistenceContextInternal()
Similar togetPersistenceContext()
, with two differences: this version performs better as it allows for inlining and probably better prediction, and it skips some checks of the current state of the session.default SharedSessionContractImplementor
getSession()
Returns this object, fulfilling the contract ofWrapperOptions
.default SessionFactoryImplementor
getSessionFactory()
Obtain the factory which created this session.UUID
getSessionIdentifier()
Obtain aUUID
which uniquely identifies this session.default Object
getSessionToken()
Obtain a "token" which uniquely identifies this session.default TypeConfiguration
getTypeConfiguration()
Obtain theTypeConfiguration
for the factory which created this session.String
guessEntityName(Object entity)
Obtain an estimate of the entity name of the given entity instance, which is not involved in an association, using only theEntityNameResolver
.Object
immediateLoad(String entityName, Object id)
Load an instance immediately.void
initializeCollection(PersistentCollection<?> collection, boolean writing)
Initialize the given collection (if not already initialized).Object
instantiate(String entityName, Object id)
Instantiate the entity class, initializing with the given identifier.Object
instantiate(EntityPersister persister, Object id)
Instantiate the entity class of the givenEntityPersister
, initializing the new instance with the given identifier.Object
internalLoad(String entityName, Object id, boolean eager, boolean nullable)
Obtain an entity instance with the given id, without checking if it was deleted or scheduled for deletion.boolean
isAutoCloseSessionEnabled()
Deprecated.there's no reason to expose this hereboolean
isClosed()
Determines whether the session is closed.boolean
isCriteriaCopyTreeEnabled()
boolean
isDefaultReadOnly()
Are entities and proxies loaded by this session read-only by default?default boolean
isEnforcingFetchGraph()
Deprecated, for removal: This API element is subject to removal in a future version.this is not used anywheredefault boolean
isEventSource()
Determines if this session implementsEventSource
.default boolean
isOpenOrWaitingForAutoClose()
Determines whether the session is open or is waiting for auto-close.default boolean
isSessionImplementor()
Does this object implementSessionImplementor
?default boolean
isStatelessSession()
Does this object implementStatelessSession
?boolean
isTransactionInProgress()
Does this session have an active Hibernate transaction, or is it associated with a JTA transaction currently in progress?void
markForRollbackOnly()
Marks current transaction, if any, for rollback only.void
prepareForQueryExecution(boolean requiresTxn)
Prepare for the execution of aQuery
orProcedureCall
void
setAutoClear(boolean enabled)
Deprecated.there's no good reason to expose this herevoid
setCacheMode(CacheMode cm)
Set the currentCacheMode
for this session.void
setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled)
default void
setEnforcingFetchGraph(boolean enforcingFetchGraph)
Deprecated, for removal: This API element is subject to removal in a future version.this is not used anywherevoid
setHibernateFlushMode(FlushMode flushMode)
Set the currentFlushMode
for this session.void
setNativeJdbcParametersIgnored(boolean nativeJdbcParametersIgnored)
boolean
shouldAutoClose()
Deprecated.there's no reason to expose this here-
Methods inherited from interface org.hibernate.resource.jdbc.spi.JdbcSessionOwner
afterTransactionBegin, afterTransactionCompletion, beforeTransactionCompletion, flushBeforeTransactionCompletion, getEventManager, getJdbcBatchSize, getJdbcConnectionAccess, getJdbcSessionContext, getSqlExceptionHelper, getTransactionCoordinator, startTransactionBoundary
-
Methods inherited from interface org.hibernate.engine.jdbc.LobCreationContext
execute, fromContext
-
Methods inherited from interface org.hibernate.query.QueryProducer
createMutationQuery, createMutationQuery, createNamedSelectionQuery, createNamedSelectionQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery
-
Methods inherited from interface org.hibernate.query.spi.QueryProducerImplementor
createMutationQuery, createMutationQuery, createMutationQuery, createNamedMutationQuery, createNamedQuery, createNamedQuery, createNativeMutationQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createQuery, createQuery, createQuery, createQuery, createQuery, getNamedNativeQuery, getNamedNativeQuery, getNamedQuery
-
Methods inherited from interface org.hibernate.SharedSessionContract
beginTransaction, close, createEntityGraph, createEntityGraph, createEntityGraph, createNamedStoredProcedureQuery, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureQuery, createStoredProcedureQuery, createStoredProcedureQuery, disableFilter, doReturningWork, doWork, enableFilter, getCriteriaBuilder, getEnabledFilter, getEntityGraph, getEntityGraphs, getJdbcBatchSize, getNamedProcedureCall, getTenantIdentifier, getTenantIdentifierValue, getTransaction, isConnected, isJoinedToTransaction, isOpen, joinTransaction, setJdbcBatchSize
-
Methods inherited from interface org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options
shouldAutoJoinTransaction
-
Methods inherited from interface org.hibernate.type.descriptor.WrapperOptions
getJdbcTimeZone, getLobCreator, getPreferredSqlTypeCodeForBoolean, useStreamForLobBinding
-
-
-
-
Method Detail
-
getFactory
SessionFactoryImplementor getFactory()
Obtain the factory which created this session.- Specified by:
getFactory
in interfaceQueryProducerImplementor
- Specified by:
getFactory
in interfaceSharedSessionContract
-
getSessionFactory
default SessionFactoryImplementor getSessionFactory()
Obtain the factory which created this session.- Specified by:
getSessionFactory
in interfaceWrapperOptions
-
getTypeConfiguration
default TypeConfiguration getTypeConfiguration()
Obtain theTypeConfiguration
for the factory which created this session.- Specified by:
getTypeConfiguration
in interfaceJavaType.CoercionContext
-
getEventListenerManager
SessionEventListenerManager getEventListenerManager()
Get theSessionEventListenerManager
associated with this session.
-
getPersistenceContext
PersistenceContext getPersistenceContext()
Get the persistence context for this session.See
getPersistenceContextInternal()
for a faster alternative.- Implementation Note:
- This method is not extremely fast: if you need to
call the
PersistenceContext
multiple times, prefer keeping a reference to it instead of invoking this method multiple times.
-
getJdbcCoordinator
JdbcCoordinator getJdbcCoordinator()
Obtain theJdbcCoordinator
for this session.
-
getJdbcServices
JdbcServices getJdbcServices()
Obtain theJdbcServices
for the factory which created this session.
-
getSessionIdentifier
UUID getSessionIdentifier()
Obtain aUUID
which uniquely identifies this session.The UUID is useful mainly for logging.
-
getSession
default SharedSessionContractImplementor getSession()
Returns this object, fulfilling the contract ofWrapperOptions
.- Specified by:
getSession
in interfaceWrapperOptions
-
getSessionToken
default Object getSessionToken()
Obtain a "token" which uniquely identifies this session.
-
isClosed
boolean isClosed()
Determines whether the session is closed.- Returns:
true
if the session is closed;false
otherwise.- API Note:
- Provided separately from
SharedSessionContract.isOpen()
as this method does not attempt any JTA synchronization registration, whereasSharedSessionContract.isOpen()
does. This one is better for most internal purposes.
-
isOpenOrWaitingForAutoClose
default boolean isOpenOrWaitingForAutoClose()
Determines whether the session is open or is waiting for auto-close.- Returns:
true
if the session is closed, or if it's waiting for auto-close;false
otherwise.
-
checkOpen
default void checkOpen()
Check whether the session is open, and if not:- mark the current transaction, if any, for rollback only, and
- throw an
IllegalStateException
. (JPA specifies this exception type.)
-
checkOpen
void checkOpen(boolean markForRollbackIfClosed)
Check whether the session is open, and if not:- if
markForRollbackIfClosed = true
, mark the current transaction, if any, for rollback only, and - throw an
IllegalStateException
. (JPA specifies this exception type.)
- if
-
prepareForQueryExecution
void prepareForQueryExecution(boolean requiresTxn)
Prepare for the execution of aQuery
orProcedureCall
-
markForRollbackOnly
void markForRollbackOnly()
Marks current transaction, if any, for rollback only.
-
getCacheTransactionSynchronization
CacheTransactionSynchronization getCacheTransactionSynchronization()
The currentCacheTransactionSynchronization
associated with this session. This may benull
if the session is not currently associated with an active transaction.
-
isTransactionInProgress
boolean isTransactionInProgress()
Does this session have an active Hibernate transaction, or is it associated with a JTA transaction currently in progress?
-
checkTransactionNeededForUpdateOperation
default void checkTransactionNeededForUpdateOperation(String exceptionMessage)
Check if an activeTransaction
is available before performing an update operation against the database.If an active transaction is necessary, but no transaction is active, a
TransactionRequiredException
is raised.- Parameters:
exceptionMessage
- the message to use for theTransactionRequiredException
-
accessTransaction
Transaction accessTransaction()
Retrieves the currentTransaction
, or creates a new transaction if there is no transaction active.This method is primarily for internal or integrator use.
- Returns:
- the
Transaction
-
generateEntityKey
EntityKey generateEntityKey(Object id, EntityPersister persister)
Instantiate anEntityKey
with the given id and for the entity represented by the givenEntityPersister
.- Parameters:
id
- The entity idpersister
- The entity persister- Returns:
- The entity key
-
getInterceptor
Interceptor getInterceptor()
Retrieves theInterceptor
associated with this session.
-
setAutoClear
@Deprecated(since="6") void setAutoClear(boolean enabled)
Deprecated.there's no good reason to expose this hereEnable or disable automatic cache clearing from after transaction completion.
-
initializeCollection
void initializeCollection(PersistentCollection<?> collection, boolean writing) throws HibernateException
Initialize the given collection (if not already initialized).- Throws:
HibernateException
-
internalLoad
Object internalLoad(String entityName, Object id, boolean eager, boolean nullable) throws HibernateException
Obtain an entity instance with the given id, without checking if it was deleted or scheduled for deletion.- When
nullable = false
, this method may create a new proxy or return an existing proxy; if it does not exist, an exception is thrown. - When
nullable = true
, the method does not create new proxies, though it might return an existing proxy; if it does not exist, anull
value is returned.
When
eager = true
, the object is eagerly fetched from the database.- Throws:
HibernateException
- When
-
immediateLoad
Object immediateLoad(String entityName, Object id) throws HibernateException
Load an instance immediately. This method is only called when lazily initializing a proxy. Do not return the proxy.- Throws:
HibernateException
-
getEntityPersister
EntityPersister getEntityPersister(@Nullable String entityName, Object object) throws HibernateException
Get theEntityPersister
for the given entity instance.- Parameters:
entityName
- optional entity nameobject
- the entity instance- Throws:
HibernateException
-
getEntityUsingInterceptor
Object getEntityUsingInterceptor(EntityKey key) throws HibernateException
Get the entity instance associated with the givenEntityKey
, calling theInterceptor
if necessary.- Throws:
HibernateException
-
getContextEntityIdentifier
Object getContextEntityIdentifier(Object object)
Return the identifier of the persistent object, or null if it is not associated with this session.
-
bestGuessEntityName
String bestGuessEntityName(Object object)
Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session.
-
bestGuessEntityName
default String bestGuessEntityName(Object object, EntityEntry entry)
Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session.
-
guessEntityName
String guessEntityName(Object entity) throws HibernateException
Obtain an estimate of the entity name of the given entity instance, which is not involved in an association, using only theEntityNameResolver
.- Throws:
HibernateException
-
instantiate
Object instantiate(String entityName, Object id) throws HibernateException
Instantiate the entity class, initializing with the given identifier.- Throws:
HibernateException
-
instantiate
Object instantiate(EntityPersister persister, Object id) throws HibernateException
Instantiate the entity class of the givenEntityPersister
, initializing the new instance with the given identifier.This is more efficient than
instantiate(String, Object)
, but not always interchangeable, since a single persister might be responsible for multiple types.- Throws:
HibernateException
-
isDefaultReadOnly
boolean isDefaultReadOnly()
Are entities and proxies loaded by this session read-only by default?
-
getCacheMode
CacheMode getCacheMode()
Get the currentCacheMode
for this session.- Specified by:
getCacheMode
in interfaceQueryProducerImplementor
-
setCriteriaCopyTreeEnabled
void setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled)
-
isCriteriaCopyTreeEnabled
boolean isCriteriaCopyTreeEnabled()
-
getNativeJdbcParametersIgnored
boolean getNativeJdbcParametersIgnored()
-
setNativeJdbcParametersIgnored
void setNativeJdbcParametersIgnored(boolean nativeJdbcParametersIgnored)
-
getFlushMode
@Deprecated(since="6") FlushModeType getFlushMode()
Deprecated.there's no good reason to expose this hereGet the currentFlushModeType
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'sFlushMode
. For the former behavior, usegetHibernateFlushMode()
instead.- Returns:
- The
FlushModeType
in effect for this Session.
-
setHibernateFlushMode
void setHibernateFlushMode(FlushMode flushMode)
Set the currentFlushMode
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's reasonable to set the session flush mode to
FlushMode.MANUAL
at the start of the session (in order skip some work and gain some extra performance).- Parameters:
flushMode
- the new flush mode
-
getHibernateFlushMode
FlushMode getHibernateFlushMode()
Get the currentFlushMode
for this session.- Specified by:
getHibernateFlushMode
in interfaceQueryProducerImplementor
- Returns:
- The flush mode
-
flush
void flush()
Flush this session.
-
isEventSource
default boolean isEventSource()
Determines if this session implementsEventSource
.Only stateful session are sources of events. If this object is a stateless session, this method return
false
.
-
asEventSource
default EventSource asEventSource()
Cast this session toEventSource
if possible.Only stateful session are sources of events. If this object is a stateless session, this method throws.
- Throws:
ClassCastException
- if the cast is not possible
-
afterScrollOperation
void afterScrollOperation()
Called after each operation on aScrollableResults
, providing an opportunity for a stateless session to clear its temporary persistence context. For a stateful session, this method does nothing.
-
shouldAutoClose
@Deprecated(since="6") boolean shouldAutoClose()
Deprecated.there's no reason to expose this hereShould this session be automatically closed after the current transaction completes?
-
isAutoCloseSessionEnabled
@Deprecated(since="6") boolean isAutoCloseSessionEnabled()
Deprecated.there's no reason to expose this hereIs auto-close at transaction completion enabled?
-
getLoadQueryInfluencers
LoadQueryInfluencers getLoadQueryInfluencers()
Get theLoadQueryInfluencers
associated with this session.- Returns:
- the
LoadQueryInfluencers
associated with this session; should never be null.
-
getExceptionConverter
ExceptionConverter getExceptionConverter()
Obtain anExceptionConverter
for reporting an error.The converter associated to a session might be lazily initialized, so only invoke this getter when there's an actual need to use it.
- Returns:
- the ExceptionConverter for this Session.
-
getConfiguredJdbcBatchSize
default Integer getConfiguredJdbcBatchSize()
Get the currently configured JDBC batch size, which might have been specified at either the session or factory level.- Returns:
- the session-level JDBC batch size is set, or the factory-level setting otherwise
- Since:
- 5.2
- See Also:
SessionFactoryOptions.getJdbcBatchSize()
,SessionFactoryBuilder.applyJdbcBatchSize(int)
-
getPersistenceContextInternal
PersistenceContext getPersistenceContextInternal()
Similar togetPersistenceContext()
, with two differences:- this version performs better as it allows for inlining and probably better prediction, and
- it skips some checks of the current state of the session.
- Returns:
- the
PersistenceContext
associated to this session.
-
autoFlushIfRequired
boolean autoFlushIfRequired(Set<String> querySpaces) throws HibernateException
detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush- Parameters:
querySpaces
- the tables named in the query.- Returns:
- true if flush is required, false otherwise.
- Throws:
HibernateException
-
autoFlushIfRequired
default boolean autoFlushIfRequired(Set<String> querySpaces, boolean skipPreFlush) throws HibernateException
- Throws:
HibernateException
-
autoPreFlush
default void autoPreFlush()
-
isEnforcingFetchGraph
@Deprecated(since="6", forRemoval=true) default boolean isEnforcingFetchGraph()
Deprecated, for removal: This API element is subject to removal in a future version.this is not used anywhereAre we currently enforcing a fetch graph?
-
setEnforcingFetchGraph
@Deprecated(since="6", forRemoval=true) default void setEnforcingFetchGraph(boolean enforcingFetchGraph)
Deprecated, for removal: This API element is subject to removal in a future version.this is not used anywhereEnable or disable fetch graph enforcement.
-
afterOperation
void afterOperation(boolean success)
Check if there is a Hibernate or JTA transaction in progress and, if there is not, flush if necessary, making sure that the connection has been committed (if it is not in autocommit mode), and finally run the after completion processing.- Parameters:
success
-true
if the operation a success
-
asSessionImplementor
default SessionImplementor asSessionImplementor()
Cast this object toSessionImplementor
, if possible.- Throws:
ClassCastException
- if the cast is not possible
-
isSessionImplementor
default boolean isSessionImplementor()
Does this object implementSessionImplementor
?
-
asStatelessSession
default StatelessSession asStatelessSession()
Cast this object toStatelessSession
, if possible.- Throws:
ClassCastException
- if the cast is not possible
-
isStatelessSession
default boolean isStatelessSession()
Does this object implementStatelessSession
?
-
-