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
,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 (such asType
,EntityPersister
andCollectionPersister
implementors A Session, through this interface and SharedSessionContractImplementor, implements:-
JdbcSessionOwner
to drive the behavior of a "JDBC session". Can therefor be used to construct a JdbcCoordinator, which (for now) models a "JDBC session" -
TransactionCoordinatorBuilder.Options
to drive the creation of theTransactionCoordinator
delegate. This allows it to be passed along toTransactionCoordinatorBuilder.buildTransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner, org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options)
-
LobCreationContext
to act as the context for JDBC LOB instance creation -
WrapperOptions
to fulfill the behavior needed while binding/extracting values to/from JDBC as part of the Type contracts
-
-
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 Modifier and Type Method Description Transaction
accessTransaction()
Provides access to the underlying transaction or creates a new transaction if one does not already exist or is active.void
afterOperation(boolean success)
Check if there is a Hibernate or JTA transaction in progress and, if there is not, flush if necessary, make sure the connection has been committed (if it is not in autocommit mode) and run the after completion processingvoid
afterScrollOperation()
EventSource
asEventSource()
default SessionImplementor
asSessionImplementor()
If this can be casted to a @SessionImplementor
, you'll get this returned after an efficient cast.default StatelessSession
asStatelessSession()
If this can be casted to a @StatelessSession
, you'll get this returned after an efficient cast.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 flushString
bestGuessEntityName(Object object)
The best guess entity name for an entity not in an associationdefault 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)void
checkOpen(boolean markForRollbackIfClosed)
Performs a check whether the Session is open, and if not: ifmarkForRollbackIfClosed
is true, marks current transaction (if one) for rollback only throws an IllegalStateException (JPA defines the exception type)default void
checkTransactionNeededForUpdateOperation(String exceptionMessage)
Check if an active Transaction is necessary for the update operation to be executed.void
flush()
EntityKey
generateEntityKey(Object id, EntityPersister persister)
Hide the changing requirements of entity key creationCacheMode
getCacheMode()
CacheTransactionSynchronization
getCacheTransactionSynchronization()
The current CacheTransactionContext associated with the Session.default Integer
getConfiguredJdbcBatchSize()
Get the currently configured JDBC batch size either at the Session-level or SessionFactory-level.Object
getContextEntityIdentifier(Object object)
Return the identifier of the persistent object, or null if not associated with the sessionEntityPersister
getEntityPersister(String entityName, Object object)
Get theEntityPersister
for any instanceObject
getEntityUsingInterceptor(EntityKey key)
Get the entity instance associated with the givenKey
, calling the Interceptor if necessarySessionEventListenerManager
getEventListenerManager()
ExceptionConverter
getExceptionConverter()
The converter associated to a Session might be lazily initialized: only invoke this getter when there is actual need to use it.SessionFactoryImplementor
getFactory()
Get the creatingSessionFactoryImplementor
jakarta.persistence.FlushModeType
getFlushMode()
Get the flush mode for this session.FlushMode
getHibernateFlushMode()
Get the current flush mode for this session.Interceptor
getInterceptor()
Retrieves the interceptor currently in use by this event source.JdbcCoordinator
getJdbcCoordinator()
JdbcServices
getJdbcServices()
LoadQueryInfluencers
getLoadQueryInfluencers()
Get the load query influencers associated with this session.PersistenceContext
getPersistenceContext()
Get the persistence context for this session.PersistenceContext
getPersistenceContextInternal()
This is similar togetPersistenceContext()
, 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.default SharedSessionContractImplementor
getSession()
Access to the current session.default SessionFactoryImplementor
getSessionFactory()
Access to the current session factory.UUID
getSessionIdentifier()
A UUID associated with each Session.default Object
getSessionToken()
A "token" that is unique to this Session.String
getTenantIdentifier()
The multi-tenancy tenant identifier, if one.default TypeConfiguration
getTypeConfiguration()
String
guessEntityName(Object entity)
The guessed entity name for an entity not in an associationObject
immediateLoad(String entityName, Object id)
Load an instance immediately.void
initializeCollection(PersistentCollection<?> collection, boolean writing)
Initialize the collection (if not already initialized)Object
instantiate(String entityName, Object id)
Instantiate the entity class, initializing with the given identifierObject
instantiate(EntityPersister persister, Object id)
Instantiate the entity class of an EntityPersister, initializing with the given identifier.Object
internalLoad(String entityName, Object id, boolean eager, boolean nullable)
Load an instance without checking if it was deleted.boolean
isAutoCloseSessionEnabled()
boolean
isClosed()
Checks whether the session is closed.boolean
isCriteriaCopyTreeEnabled()
boolean
isDefaultReadOnly()
default boolean
isEnforcingFetchGraph()
boolean
isEventSource()
default boolean
isOpenOrWaitingForAutoClose()
Checks whether the session is open or is waiting for auto-closedefault boolean
isSessionImplementor()
default boolean
isStatelessSession()
boolean
isTransactionInProgress()
Does thisSession
have an active Hibernate transaction or is there a JTA transaction in progress?void
markForRollbackOnly()
Marks current transaction (if one) for rollback onlyvoid
prepareForQueryExecution(boolean requiresTxn)
Prepare for the execution of aQuery
orProcedureCall
void
setAutoClear(boolean enabled)
Enable/disable automatic cache clearing from after transaction completion (for EJB3)void
setCacheMode(CacheMode cm)
void
setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled)
default void
setEnforcingFetchGraph(boolean enforcingFetchGraph)
void
setHibernateFlushMode(FlushMode flushMode)
Set the flush mode for this session.boolean
shouldAutoClose()
-
Methods inherited from interface org.hibernate.resource.jdbc.spi.JdbcSessionOwner
afterTransactionBegin, afterTransactionCompletion, beforeTransactionCompletion, flushBeforeTransactionCompletion, getJdbcBatchSize, getJdbcConnectionAccess, getJdbcSessionContext, getTransactionCoordinator, startTransactionBoundary
-
Methods inherited from interface org.hibernate.engine.jdbc.LobCreationContext
execute
-
Methods inherited from interface org.hibernate.query.QueryProducer
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, createNamedStoredProcedureQuery, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureQuery, createStoredProcedureQuery, createStoredProcedureQuery, doReturningWork, doWork, getCriteriaBuilder, getJdbcBatchSize, getNamedProcedureCall, getTransaction, isConnected, isOpen, 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()
Get the creatingSessionFactoryImplementor
- Specified by:
getFactory
in interfaceQueryProducerImplementor
-
getSessionFactory
default SessionFactoryImplementor getSessionFactory()
Description copied from interface:WrapperOptions
Access to the current session factory.- Specified by:
getSessionFactory
in interfaceWrapperOptions
-
getTypeConfiguration
default TypeConfiguration getTypeConfiguration()
- Specified by:
getTypeConfiguration
in interfaceJavaType.CoercionContext
-
getEventListenerManager
SessionEventListenerManager getEventListenerManager()
-
getPersistenceContext
PersistenceContext getPersistenceContext()
Get the persistence context for this session. See alsogetPersistenceContextInternal()
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.
-
getJdbcCoordinator
JdbcCoordinator getJdbcCoordinator()
-
getJdbcServices
JdbcServices getJdbcServices()
-
getTenantIdentifier
String getTenantIdentifier()
The multi-tenancy tenant identifier, if one.- Specified by:
getTenantIdentifier
in interfaceSharedSessionContract
- Returns:
- The tenant identifier; may be
null
-
getSessionIdentifier
UUID getSessionIdentifier()
A UUID associated with each Session. Useful mainly for logging.- Returns:
- The UUID
-
getSession
default SharedSessionContractImplementor getSession()
Description copied from interface:WrapperOptions
Access to the current session.- Specified by:
getSession
in interfaceWrapperOptions
-
getSessionToken
default Object getSessionToken()
A "token" that is unique to this Session.- Returns:
- The token
-
isClosed
boolean isClosed()
Checks whether the session is closed. Provided separately fromSharedSessionContract.isOpen()
as this method does not attempt any JTA synchronization registration, whereasSharedSessionContract.isOpen()
does; which makes this one nicer to use for most internal purposes.- Returns:
true
if the session is closed;false
otherwise.
-
isOpenOrWaitingForAutoClose
default boolean isOpenOrWaitingForAutoClose()
Checks 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()
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)
-
checkOpen
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)
- if
-
prepareForQueryExecution
void prepareForQueryExecution(boolean requiresTxn)
Prepare for the execution of aQuery
orProcedureCall
-
markForRollbackOnly
void markForRollbackOnly()
Marks current transaction (if one) for rollback only
-
getCacheTransactionSynchronization
CacheTransactionSynchronization getCacheTransactionSynchronization()
The current CacheTransactionContext associated with the Session. This may returnnull
when the Session is not currently part of a transaction.
-
isTransactionInProgress
boolean isTransactionInProgress()
Does thisSession
have an active Hibernate transaction or is there a JTA transaction in progress?
-
checkTransactionNeededForUpdateOperation
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
- the message to use for the TransactionRequiredException
-
accessTransaction
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:
- the transaction
-
generateEntityKey
EntityKey generateEntityKey(Object id, EntityPersister persister)
Hide the changing requirements of entity key creation- Parameters:
id
- The entity idpersister
- The entity persister- Returns:
- The entity key
-
getInterceptor
Interceptor getInterceptor()
Retrieves the interceptor currently in use by this event source.- Returns:
- The interceptor.
-
setAutoClear
void setAutoClear(boolean enabled)
Enable/disable automatic cache clearing from after transaction completion (for EJB3)
-
initializeCollection
void initializeCollection(PersistentCollection<?> collection, boolean writing) throws HibernateException
Initialize the collection (if not already initialized)- Throws:
HibernateException
-
internalLoad
Object internalLoad(String entityName, Object 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, returnnull
.When
eager
is enabled, the object is eagerly fetched- Throws:
HibernateException
-
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(String entityName, Object object) throws HibernateException
Get theEntityPersister
for any 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 givenKey
, calling the Interceptor if necessary- Throws:
HibernateException
-
getContextEntityIdentifier
Object getContextEntityIdentifier(Object object)
Return the identifier of the persistent object, or null if not associated with the session
-
bestGuessEntityName
String bestGuessEntityName(Object object)
The best guess entity name for an entity not in an association
-
guessEntityName
String guessEntityName(Object entity) throws HibernateException
The guessed entity name for an entity not in an association- 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 an EntityPersister, initializing with the given identifier. This is more efficient thaninstantiate(String, Object)
but not always interchangeable: a single persister might be responsible for multiple types.- Throws:
HibernateException
-
isDefaultReadOnly
boolean isDefaultReadOnly()
-
getCacheMode
CacheMode getCacheMode()
- Specified by:
getCacheMode
in interfaceQueryProducerImplementor
-
setCacheMode
void setCacheMode(CacheMode cm)
-
setCriteriaCopyTreeEnabled
void setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled)
-
isCriteriaCopyTreeEnabled
boolean isCriteriaCopyTreeEnabled()
-
getFlushMode
jakarta.persistence.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'sFlushMode
. For the former behavior, usegetHibernateFlushMode()
instead.- Returns:
- The FlushModeType in effect for this Session.
-
setHibernateFlushMode
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
- the new flush mode
-
getHibernateFlushMode
FlushMode getHibernateFlushMode()
Get the current flush mode for this session.- Specified by:
getHibernateFlushMode
in interfaceQueryProducerImplementor
- Returns:
- The flush mode
-
flush
void flush()
-
isEventSource
boolean isEventSource()
-
asEventSource
EventSource asEventSource()
-
afterScrollOperation
void afterScrollOperation()
-
shouldAutoClose
boolean shouldAutoClose()
-
isAutoCloseSessionEnabled
boolean isAutoCloseSessionEnabled()
-
getLoadQueryInfluencers
LoadQueryInfluencers getLoadQueryInfluencers()
Get the load query influencers associated with this session.- Returns:
- the load query influencers associated with this session; should never be null.
-
getExceptionConverter
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:
- the ExceptionConverter for this Session.
-
getConfiguredJdbcBatchSize
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:
- Session-level or SessionFactory-level JDBC batch size.
- Since:
- 5.2
- See Also:
SessionFactoryOptions.getJdbcBatchSize()
,SessionFactoryBuilder.applyJdbcBatchSize(int)
-
getPersistenceContextInternal
PersistenceContext getPersistenceContextInternal()
This is similar togetPersistenceContext()
, 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:
- 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
-
isEnforcingFetchGraph
default boolean isEnforcingFetchGraph()
-
setEnforcingFetchGraph
default void setEnforcingFetchGraph(boolean enforcingFetchGraph)
-
afterOperation
void afterOperation(boolean success)
Check if there is a Hibernate or JTA transaction in progress and, if there is not, flush if necessary, make sure the connection has been committed (if it is not in autocommit mode) and run the after completion processing- Parameters:
success
- Was the operation a success
-
asSessionImplementor
default SessionImplementor asSessionImplementor()
If this can be casted to a @SessionImplementor
, you'll get this returned after an efficient cast.- Throws:
ClassCastException
- if this is not compatible!
-
isSessionImplementor
default boolean isSessionImplementor()
-
asStatelessSession
default StatelessSession asStatelessSession()
If this can be casted to a @StatelessSession
, you'll get this returned after an efficient cast.- Throws:
ClassCastException
- if this is not compatible!
-
isStatelessSession
default boolean isStatelessSession()
-
-