Package org.hibernate.engine.spi
Interface SharedSessionContractImplementor
-
- All Superinterfaces:
JdbcSessionOwner,LobCreationContext,QueryProducer,QueryProducerImplementor,java.io.Serializable,SharedSessionContract,TransactionCoordinatorBuilder.Options,WrapperOptions
- All Known Subinterfaces:
EventSource,SessionImplementor
- All Known Implementing Classes:
SessionDelegatorBaseImpl
public interface SharedSessionContractImplementor extends SharedSessionContract, JdbcSessionOwner, TransactionCoordinatorBuilder.Options, LobCreationContext, WrapperOptions, QueryProducerImplementor
Defines the internal contract shared betweenSessionandStatelessSessionas used by other parts of Hibernate (such asType,EntityPersisterandCollectionPersisterimplementors A Session, through this interface and SharedSessionContractImplementor, implements:-
JdbcSessionOwnerto drive the behavior of a "JDBC session". Can therefor be used to construct a JdbcCoordinator, which (for now) models a "JDBC session" -
TransactionCoordinatorBuilder.Optionsto drive the creation of theTransactionCoordinatordelegate. This allows it to be passed along toTransactionCoordinatorBuilder.buildTransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner, org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options) -
LobCreationContextto act as the context for JDBC LOB instance creation -
WrapperOptionsto 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 Deprecated Methods Modifier and Type Method Description TransactionaccessTransaction()Provides access to the underlying transaction or creates a new transaction if one does not already exist or is active.voidafterScrollOperation()java.lang.StringbestGuessEntityName(java.lang.Object object)The best guess entity name for an entity not in an associationdefault voidcheckOpen()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)voidcheckOpen(boolean markForRollbackIfClosed)Performs a check whether the Session is open, and if not: ifmarkForRollbackIfClosedis true, marks current transaction (if one) for rollback only throws an IllegalStateException (JPA defines the exception type)default voidcheckTransactionNeededForUpdateOperation(java.lang.String exceptionMessage)Check if an active Transaction is necessary for the update operation to be executed.java.sql.Connectionconnection()<T> QueryImplementor<T>createQuery(java.lang.String jpaqlString, java.lang.Class<T> resultClass, Selection 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)intexecuteNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)Execute a native SQL update or delete queryintexecuteUpdate(java.lang.String query, QueryParameters queryParameters)Execute a HQL update or delete queryvoidflush()EntityKeygenerateEntityKey(java.io.Serializable id, EntityPersister persister)Hide the changing requirements of entity key creationCacheModegetCacheMode()CacheTransactionSynchronizationgetCacheTransactionSynchronization()The current CacheTransactionContext associated with the Session.default java.lang.IntegergetConfiguredJdbcBatchSize()Get the currently configured JDBC batch size either at the Session-level or SessionFactory-level.java.io.SerializablegetContextEntityIdentifier(java.lang.Object object)Return the identifier of the persistent object, or null if not associated with the sessionintgetDontFlushFromFind()EntityPersistergetEntityPersister(java.lang.String entityName, java.lang.Object object)Get the EntityPersister for any instancejava.lang.ObjectgetEntityUsingInterceptor(EntityKey key)Get the entity instance associated with the given Key, calling the Interceptor if necessarySessionEventListenerManagergetEventListenerManager()ExceptionConvertergetExceptionConverter()The converter associated to a Session might be lazily initialized: only invoke this getter when there is actual need to use it.SessionFactoryImplementorgetFactory()Get the creating SessionFactoryImplementorFlushModeTypegetFlushMode()Get the flush mode for this session.FlushModegetHibernateFlushMode()Get the current flush mode for this session.InterceptorgetInterceptor()Retrieves the interceptor currently in use by this event source.JdbcCoordinatorgetJdbcCoordinator()JdbcServicesgetJdbcServices()LoadQueryInfluencersgetLoadQueryInfluencers()Get the load query influencers associated with this session.PersistenceContextgetPersistenceContext()Get the persistence context for this session.PersistenceContextgetPersistenceContextInternal()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.java.util.UUIDgetSessionIdentifier()A UUID associated with each Session.java.lang.StringgetTenantIdentifier()The multi-tenancy tenant identifier, if one.default longgetTimestamp()Deprecated.(since 5.3) UsegetTransactionStartTimestamp()instead.longgetTransactionStartTimestamp()Deprecated.no longer supported, when the Second Level Cache is enabled {CacheTransactionSynchronization.getCachingTimestamp()} can be used.java.lang.StringguessEntityName(java.lang.Object entity)The guessed entity name for an entity not in an associationjava.lang.ObjectimmediateLoad(java.lang.String entityName, java.io.Serializable id)Load an instance immediately.voidinitializeCollection(PersistentCollection collection, boolean writing)Initialize the collection (if not already initialized)java.lang.Objectinstantiate(java.lang.String entityName, java.io.Serializable id)Instantiate the entity class, initializing with the given identifierjava.lang.Objectinstantiate(EntityPersister persister, java.io.Serializable id)Instantiate the entity class of an EntityPersister, initializing with the given identifier.java.lang.ObjectinternalLoad(java.lang.String entityName, java.io.Serializable id, boolean eager, boolean nullable)Load an instance without checking if it was deleted.booleanisAutoCloseSessionEnabled()booleanisClosed()Checks whether the session is closed.default booleanisEnforcingFetchGraph()booleanisEventSource()default booleanisOpenOrWaitingForAutoClose()Checks whether the session is open or is waiting for auto-closedefault booleanisQueryParametersValidationEnabled()booleanisTransactionInProgress()Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?java.util.Iteratoriterate(java.lang.String query, QueryParameters queryParameters)Execute an iterate() queryjava.util.IteratoriterateFilter(java.lang.Object collection, java.lang.String filter, QueryParameters queryParameters)Iterate a filterjava.util.Listlist(java.lang.String query, QueryParameters queryParameters)Execute a find() queryjava.util.Listlist(Criteria criteria)Execute a criteria queryjava.util.Listlist(NativeSQLQuerySpecification spec, QueryParameters queryParameters)Execute a native SQL query, and return the results as a fully built list.java.util.ListlistCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)Execute an SQL Queryjava.util.ListlistFilter(java.lang.Object collection, java.lang.String filter, QueryParameters queryParameters)Execute a filtervoidmarkForRollbackOnly()Marks current transaction (if one) for rollback onlyScrollableResultsImplementorscroll(java.lang.String query, QueryParameters queryParameters)Execute a scroll() queryScrollableResultsImplementorscroll(Criteria criteria, ScrollMode scrollMode)Execute a criteria queryScrollableResultsImplementorscroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters)Execute a native SQL query, and return the results as a scrollable result.ScrollableResultsImplementorscrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)Execute an SQL QueryvoidsetAutoClear(boolean enabled)Enable/disable automatic cache clearing from after transaction completion (for EJB3)voidsetCacheMode(CacheMode cm)default voidsetEnforcingFetchGraph(boolean enforcingFetchGraph)voidsetFlushMode(FlushMode flushMode)Deprecated.(since 5.2) usesetHibernateFlushMode(FlushMode)insteadvoidsetHibernateFlushMode(FlushMode flushMode)Set the flush mode for this session.booleanshouldAutoClose()-
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
createQuery, createQuery, createQuery
-
Methods inherited from interface org.hibernate.query.spi.QueryProducerImplementor
createNamedQuery, createNamedQuery, createNativeQuery, createNativeQuery, createNativeQuery, createQuery, createQuery, createSQLQuery, getNamedNativeQuery, getNamedQuery, getNamedSQLQuery
-
Methods inherited from interface org.hibernate.SharedSessionContract
beginTransaction, close, createCriteria, createCriteria, createCriteria, createCriteria, createQuery, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureCall, doReturningWork, doWork, getJdbcBatchSize, getNamedProcedureCall, getNamedQuery, 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, remapSqlTypeDescriptor, useStreamForLobBinding
-
-
-
-
Method Detail
-
getFactory
SessionFactoryImplementor getFactory()
Get the creating SessionFactoryImplementor- Specified by:
getFactoryin interfaceQueryProducerImplementor
-
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
java.lang.String getTenantIdentifier()
The multi-tenancy tenant identifier, if one.- Specified by:
getTenantIdentifierin interfaceSharedSessionContract- Returns:
- The tenant identifier; may be
null
-
getSessionIdentifier
java.util.UUID getSessionIdentifier()
A UUID associated with each Session. Useful mainly for logging.- Returns:
- The UUID
-
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:
trueif the session is closed;falseotherwise.
-
isOpenOrWaitingForAutoClose
default boolean isOpenOrWaitingForAutoClose()
Checks whether the session is open or is waiting for auto-close- Returns:
trueif the session is closed or if it's waiting for auto-close;falseotherwise.
-
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
markForRollbackIfClosedis true, marks current transaction (if one) for rollback only - throws an IllegalStateException (JPA defines the exception type)
- if
-
markForRollbackOnly
void markForRollbackOnly()
Marks current transaction (if one) for rollback only
-
getTransactionStartTimestamp
@Deprecated 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.
-
getTimestamp
@Deprecated default long getTimestamp()
Deprecated.(since 5.3) UsegetTransactionStartTimestamp()instead.
-
getCacheTransactionSynchronization
CacheTransactionSynchronization getCacheTransactionSynchronization()
The current CacheTransactionContext associated with the Session. This may returnnullwhen the Session is not currently part of a transaction.
-
isTransactionInProgress
boolean isTransactionInProgress()
Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?
-
checkTransactionNeededForUpdateOperation
default void checkTransactionNeededForUpdateOperation(java.lang.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(java.io.Serializable 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
java.lang.Object internalLoad(java.lang.String entityName, java.io.Serializable id, boolean eager, boolean nullable) throws HibernateExceptionLoad 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- Throws:
HibernateException
-
immediateLoad
java.lang.Object immediateLoad(java.lang.String entityName, java.io.Serializable id) throws HibernateExceptionLoad an instance immediately. This method is only called when lazily initializing a proxy. Do not return the proxy.- Throws:
HibernateException
-
list
java.util.List list(java.lang.String query, QueryParameters queryParameters) throws HibernateExceptionExecute a find() query- Throws:
HibernateException
-
iterate
java.util.Iterator iterate(java.lang.String query, QueryParameters queryParameters) throws HibernateExceptionExecute an iterate() query- Throws:
HibernateException
-
scroll
ScrollableResultsImplementor scroll(java.lang.String query, QueryParameters queryParameters) throws HibernateException
Execute a scroll() query- Throws:
HibernateException
-
scroll
ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode)
Execute a criteria query
-
list
java.util.List list(Criteria criteria)
Execute a criteria query
-
listFilter
java.util.List listFilter(java.lang.Object collection, java.lang.String filter, QueryParameters queryParameters) throws HibernateExceptionExecute a filter- Throws:
HibernateException
-
iterateFilter
java.util.Iterator iterateFilter(java.lang.Object collection, java.lang.String filter, QueryParameters queryParameters) throws HibernateExceptionIterate a filter- Throws:
HibernateException
-
getEntityPersister
EntityPersister getEntityPersister(java.lang.String entityName, java.lang.Object object) throws HibernateException
Get the EntityPersister for any instance- Parameters:
entityName- optional entity nameobject- the entity instance- Throws:
HibernateException
-
getEntityUsingInterceptor
java.lang.Object getEntityUsingInterceptor(EntityKey key) throws HibernateException
Get the entity instance associated with the given Key, calling the Interceptor if necessary- Throws:
HibernateException
-
getContextEntityIdentifier
java.io.Serializable getContextEntityIdentifier(java.lang.Object object)
Return the identifier of the persistent object, or null if not associated with the session
-
bestGuessEntityName
java.lang.String bestGuessEntityName(java.lang.Object object)
The best guess entity name for an entity not in an association
-
guessEntityName
java.lang.String guessEntityName(java.lang.Object entity) throws HibernateExceptionThe guessed entity name for an entity not in an association- Throws:
HibernateException
-
instantiate
java.lang.Object instantiate(java.lang.String entityName, java.io.Serializable id) throws HibernateExceptionInstantiate the entity class, initializing with the given identifier- Throws:
HibernateException
-
instantiate
java.lang.Object instantiate(EntityPersister persister, java.io.Serializable id) throws HibernateException
Instantiate the entity class of an EntityPersister, initializing with the given identifier. This is more efficient thaninstantiate(String, Serializable)but not always interchangeable: a single persister might be responsible for multiple types.- Throws:
HibernateException
-
listCustomQuery
java.util.List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException
Execute an SQL Query- Throws:
HibernateException
-
scrollCustomQuery
ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException
Execute an SQL Query- Throws:
HibernateException
-
list
java.util.List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException
Execute a native SQL query, and return the results as a fully built list.- Parameters:
spec- The specification of the native SQL query to execute.queryParameters- The parameters by which to perform the execution.- Returns:
- The result list.
- Throws:
HibernateException
-
scroll
ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
Execute a native SQL query, and return the results as a scrollable result.- Parameters:
spec- The specification of the native SQL query to execute.queryParameters- The parameters by which to perform the execution.- Returns:
- The resulting scrollable result.
- Throws:
HibernateException
-
getDontFlushFromFind
int getDontFlushFromFind()
-
executeUpdate
int executeUpdate(java.lang.String query, QueryParameters queryParameters) throws HibernateExceptionExecute a HQL update or delete query- Throws:
HibernateException
-
executeNativeUpdate
int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException
Execute a native SQL update or delete query- Throws:
HibernateException
-
getCacheMode
CacheMode getCacheMode()
- Specified by:
getCacheModein interfaceQueryProducerImplementor
-
setCacheMode
void setCacheMode(CacheMode cm)
-
setFlushMode
@Deprecated void setFlushMode(FlushMode flushMode)
Deprecated.(since 5.2) usesetHibernateFlushMode(FlushMode)insteadSet 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 toFlushMode.MANUALat the start of the session (in order to achieve some extra performance).- Parameters:
flushMode- the new flush mode
-
getFlushMode
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 JPAFlushModeTyperather 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 toFlushMode.MANUALat 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:
getHibernateFlushModein interfaceQueryProducerImplementor- Returns:
- The flush mode
-
connection
java.sql.Connection connection()
-
flush
void flush()
-
isEventSource
boolean isEventSource()
-
afterScrollOperation
void afterScrollOperation()
-
shouldAutoClose
boolean shouldAutoClose()
-
isAutoCloseSessionEnabled
boolean isAutoCloseSessionEnabled()
-
isQueryParametersValidationEnabled
default boolean isQueryParametersValidationEnabled()
-
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 java.lang.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 or SessionFactory-level JDBC batch size.
- Since:
- 5.2
- See Also:
SessionFactoryOptions.getJdbcBatchSize(),SessionFactoryBuilder.applyJdbcBatchSize(int)
-
createQuery
@Deprecated <T> QueryImplementor<T> createQuery(java.lang.String jpaqlString, java.lang.Class<T> resultClass, Selection 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:
- The typed query
-
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.
-
isEnforcingFetchGraph
default boolean isEnforcingFetchGraph()
-
setEnforcingFetchGraph
default void setEnforcingFetchGraph(boolean enforcingFetchGraph)
-
-