Class SessionImpl
- All Implemented Interfaces:
EntityManager,Serializable,AutoCloseable,LobCreationContext,SessionImplementor,SharedSessionContractImplementor,EventSource,LoadAccessContext,QueryProducer,QueryProducerImplementor,JdbcSessionOwner,TransactionCoordinatorBuilder.Options,Session,SharedSessionContract,JavaType.CoercionContext,WrapperOptions
Session API.
Exposes two interfaces:
Sessionto the application, andSessionImplementorandEventSource(both SPI interfaces) to other subsystems.
This class is not thread-safe.
- See Also:
- Implementation Note:
- The
SessionImpldoes not directly perform operations against the database or second-level cache. Instead, it is anEventSource, raising events which are processed by various implementations of the listener interfaces defined byorg.hibernate.event.spi. These listeners typically placeEntityActioninstances on theActionQueueassociated with the session, and such actions are executed asynchronously when the session is flushed. The motivation behind this architecture is two-fold: first, it enables customization by sophisticated extensions to Hibernate ORM, and, second, it enables the transactional write-behind semantics of a stateful session. The stateful session holds its state in an instance ofStatefulPersistenceContext, which we may view as the first-level cache associated with the session.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.hibernate.engine.jdbc.LobCreationContext
LobCreationContext.Callback<T> -
Field Summary
Fields inherited from class org.hibernate.internal.AbstractSharedSessionContract
closed, waitingForAutoClose -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListeners(SessionEventListener... listeners) Add one or more listeners to the Sessionprotected voidaddSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) voidafterOperation(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.voidCalled after each operation on aScrollableResults, providing an opportunity for a stateless session to clear its temporary persistence context.voidAn after-begin callback from the coordinator to its owner.voidafterTransactionCompletion(boolean successful, boolean delayed) An after-completion callback to the owner.protected voidapplyLockOptionsHint(SelectionQuery<?> query) protected voidapplyQuerySettingsAndHints(Query<?> query) protected voidapplyQuerySettingsAndHints(SelectionQuery<?> query) Cast this session toEventSourceif possible.booleanautoFlushIfRequired(Set<String> querySpaces) detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flushbooleanautoFlushIfRequired(Set<String> querySpaces, boolean skipPreFlush) detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flushvoidvoidA before-completion callback to the owner.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(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.<T> IdentifierLoadAccessImpl<T> Create anIdentifierLoadAccessinstance to retrieve an instance of the given entity type by its primary key.<T> IdentifierLoadAccessImpl<T> Create anIdentifierLoadAccessinstance to retrieve an instance of the named entity type by its primary key.<T> MultiIdentifierLoadAccess<T> byMultipleIds(Class<T> entityClass) Create aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the given entity type by their primary key values, using batching.<T> MultiIdentifierLoadAccess<T> byMultipleIds(String entityName) Create aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the named entity type by their primary key values, using batching.<T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(Class<T> entityClass) Create aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the given entity type by their by natural id values, using batching.<T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(String entityName) Create aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the named entity type by their by natural id values, using batching.<T> NaturalIdLoadAccess<T> byNaturalId(Class<T> entityClass) Create aNaturalIdLoadAccessinstance to retrieve an instance of the given entity type by its natural id, which may be a composite natural id.<T> NaturalIdLoadAccess<T> byNaturalId(String entityName) Create aNaturalIdLoadAccessinstance to retrieve an instance of the named entity type by its natural id, which may be a composite natural id.<T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(Class<T> entityClass) Create aSimpleNaturalIdLoadAccessinstance to retrieve an instance of the given entity type by its natural id, which must be a simple (non-composite) value.<T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(String entityName) Create aSimpleNaturalIdLoadAccessinstance to retrieve an instance of the named entity type by its natural id, which must be a simple (non-composite) value.voidCancel the execution of the current query.protected voidprotected voidvoidCallback to check whether the session is "active"protected voidprotected voidcheckTransactionNeededForLock(LockMode lockMode) protected voidclear all the internal collections, just to help the garbage collector, does not clear anything that is needed during the afterTransactionCompletion() phasevoidclear()Completely clear the persistence context.voidclose()End the session by releasing the JDBC connection and cleaning up.voidbooleanbooleanDetermine if the given entity is associated with this session.protected ActionQueueObtain aProcedureCallbased on a named templateprotected PersistenceContext<T> QueryImplementor<T> createQuery(CriteriaSelect<T> selectQuery) createStoredProcedureCall(String procedureName) Create aProcedureCallto a stored procedure.createStoredProcedureCall(String procedureName, Class<?>... resultClasses) Create aProcedureCallto a stored procedure with the given result set entity mappings.createStoredProcedureCall(String procedureName, String... resultSetMappings) Create aProcedureCallto a stored procedure with the given result set entity mappings.createStoredProcedureQuery(String procedureName) Create aProcedureCallto a stored procedure.createStoredProcedureQuery(String procedureName, Class... resultClasses) Create aProcedureCallto a stored procedure with the given result set entity mappings.createStoredProcedureQuery(String procedureName, String... resultSetMappings) Create aProcedureCallto a stored procedure with the given result set entity mappings.voidvoiddelete(String entityName, Object object, boolean isCascadeDeleteEnabled, DeleteContext transientEntities) Cascade delete an entity instancevoidRemove this instance from the session cache.protected CacheModedetermineAppropriateLocalCacheMode(Map<String, Object> localProperties) voiddisableFetchProfile(String name) Disable thefetch profilewith the given name in this session.voidenableFetchProfile(String name) Enable thefetch profilewith the given name in this session.voidremove any hard references to the entity that are held by the infrastructure (references held by application or other persistent instances are okay)<T> Tfind(EntityGraph<T> entityGraph, Object primaryKey, FindOption... options) <T> TReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.<T> Tfind(Class<T> entityClass, Object primaryKey, FindOption... options) <T> Tfind(Class<T> entityClass, Object primaryKey, LockModeType lockModeType) <T> Tfind(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> properties) <T> TReturn the persistent instance of the named entity type with the given identifier, or null if there is no such persistent instance.find(String entityName, Object primaryKey, FindOption... options) Return the persistent instance of the named entity type with the given identifier using the specified options, or null if there is no such persistent instance.<E> List<E> findMultiple(EntityGraph<E> entityGraph, List<?> ids, FindOption... options) Return the persistent instances of the root entity of the givenEntityGraphwith the given identifiers as a list, fetching the associations specified by the graph, which is interpreted as a load graph.<E> List<E> findMultiple(Class<E> entityType, List<?> ids, FindOption... options) Return the persistent instances of the given entity class with the given identifiers as a list.voidflush()Flush this session.voidvoidforceFlush(EntityEntry entityEntry) Initiate a flush to force deletion of a re-persisted entity.voidforceFlush(EntityKey key) Initiate a flush to force deletion of a re-persisted entity.<T> TReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.<T> TDeprecated.<T> Tget(Class<T> entityClass, Object id, LockOptions lockOptions) Deprecated.Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.Deprecated.get(String entityName, Object id, LockOptions lockOptions) Deprecated.Get theActionQueueassociated with this session.The JPA-definedCacheRetrieveMode.The JPA-definedCacheStoreMode.getContextEntityIdentifier(Object object) Get the id value for an object that is actually associated with the session.getCurrentLockMode(Object object) Determine the current lock mode held on the given managed instance associated with this session.getEntityName(Object object) Return the entity name for the given persistent entity.getEntityPersister(String entityName, Object object) Get theEntityPersisterfor the given entity instance.Get the entity instance associated with the givenEntityKey, calling theInterceptorif necessary.intGet the maximum batch size for batch fetching associations by id in this session.Get the current JPA flush mode for this session.Get the currentFlushModefor this session.getIdentifier(Object object) Return the identifier value of the given entity associated with this session.Get theLoadQueryInfluencersassociated with this session.getLockMode(Object entity) Collection<?> Obtain the collection of all managed entities which belong to this persistence context.<E> Collection<E> getManagedEntities(EntityType<E> entityType) Obtain a collection of all managed entities of the given type which belong to this persistence context.<E> Collection<E> getManagedEntities(Class<E> entityType) Obtain a collection of all managed entities of the given type which belong to this persistence context.Collection<?> getManagedEntities(String entityName) Obtain a collection of all managed instances of the entity type with the given entity name which belong to this persistence context.Get the persistence context for this session.Similar toSharedSessionContractImplementor.getPersistenceContext(), 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.protected Boolean<T> TgetReference(Class<T> entityClass, Object id) Return a reference to the persistent instance with the given class and identifier, making the assumption that the instance is still persistent in the database.getReference(String entityName, Object id) Return a reference to the persistent instance of the given named entity with the given identifier, making the assumption that the instance is still persistent in the database.<T> TgetReference(T object) Return a reference to the persistent instance with the same identity as the given instance, which might be detached, making the assumption that the instance is still persistent in the database.Returns this object, fulfilling the contract ofWrapperOptions.Get the statistics for this session.guessEntityName(Object object) Obtain an estimate of the entity name of the given entity instance, which is not involved in an association, using only theEntityNameResolver.immediateLoad(String entityName, Object id) Load the data for the object with the specified id into a newly created object.voidinitializeCollection(PersistentCollection<?> collection, boolean writing) Initialize the given collection (if not already initialized).instantiate(String entityName, Object id) Deprecated.instantiate(EntityPersister persister, Object id) give the interceptor an opportunity to override the default instantiationinternalLoad(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.protected static LoadEventListener.LoadTypeinternalLoadType(boolean eager, boolean nullable) booleanShould this session be automatically closed after the current transaction completes?booleanAre entities and proxies loaded by this session read-only by default?booleanisDirty()Does this session contain any changes which must be synchronized with the database? In other words, would any DML operations be executed if we flushed this session?booleanDetermines if this session implementsEventSource.booleanisFetchProfileEnabled(String name) Is thefetch profilewith the given name enabled in this session?booleanbooleanisOpen()Check if the session is still open.booleanisReadOnly(Object entityOrProxy) Is the specified entity or proxy read-only?booleanDetermine if subselect fetching is enabled in this session.voidRead the persistent state associated with the given identifier into the given transient instance.load(LoadEventListener.LoadType loadType, Object id, String entityName, LockOptions lockOptions, Boolean readOnly) Efficiently fire aLoadEventwith the given type and return the resulting entity instance or proxy.loadFromSecondLevelCache(EntityPersister persister, EntityKey entityKey, Object instanceToLoad, LockMode lockMode) Attempts to load the entity from the second-level cache.voidlock(Object entity, LockModeType lockModeType) voidlock(Object entity, LockModeType lockModeType, LockOption... options) voidvoidObtain the specified lock level on the given managed instance associated with this session.voidlock(Object object, LockMode lockMode, LockOption... lockOptions) Obtain the specified lock level on the given managed instance associated with this session, applying any other specified options.voidlock(Object object, LockOptions lockOptions) Obtain a lock on the given managed instance associated with this session, using the given lock options.voidlock(String entityName, Object object, LockOptions lockOptions) Cascade the lock operation to the given child entity.protected static <T> voidlogIgnoringEntityNotFound(Class<T> entityClass, Object primaryKey) protected LoadEventmakeLoadEvent(String entityName, Object id, Boolean readOnly, boolean isAssociationFetch) Helper to avoid creating many new instances ofLoadEvent.protected LoadEventmakeLoadEvent(String entityName, Object id, Boolean readOnly, LockOptions lockOptions) Helper to avoid creating many new instances ofLoadEvent.protected PostLoadEventmakePostLoadEvent(EntityPersister persister, Object id, Object entity) Helper to avoid creating many new instances ofPostLoadEvent.voidmerge(String entityName, Object object, MergeContext copiedAlready) Cascade merge an entity instance<T> TCopy the state of the given object onto the persistent object with the same identifier.<T> Tmerge(T object) Copy the state of the given object onto the persistent object with the same identifier.<T> Tmerge(T object, EntityGraph<?> loadGraph) Copy the state of the given object onto the persistent object with the same identifier.voidMake a transient instance persistent and mark it for later insertion in the database.voidMake a transient instance persistent and mark it for later insertion in the database.voidpersist(String entityName, Object object, PersistContext copiedAlready) Cascade persist an entity instancevoidpersistOnFlush(String entityName, Object object, PersistContext copiedAlready) Cascade persist an entity instance during the flush processvoidCallback to pulse the transaction coordinatorprotected static BooleanreadOnlyHint(Map<String, Object> properties) voidReread the state of the given managed instance associated with this session from the underlying database.voidrefresh(Object entity, LockModeType lockModeType) voidvoidrefresh(Object entity, RefreshOption... options) voidvoidrefresh(Object object, LockOptions lockOptions) Reread the state of the given managed instance from the underlying database, obtaining the givenLockMode.voidrefresh(String entityName, Object object, RefreshContext refreshedAlready) Cascade refresh an entity instancevoidRegisters the given process for execution after transaction completion.protected voidreleaseLoadEvent(LoadEvent event) protected voidvoidMark a persistence instance associated with this session for removal from the underlying database.voidremoveOrphanBeforeUpdates(String entityName, Object child) A specialized type of deletion for orphan removal that must occur prior to queued inserts and updates.protected voidremoveSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) voidreplicate(Object obj, ReplicationMode replicationMode) Persist the state of the given detached instance, reusing the current identifier value.voidreplicate(String entityName, Object obj, ReplicationMode replicationMode) Persist the state of the given detached instance, reusing the current identifier value.Obtain aSessionbuilder with the ability to copy certain information from this session.voidsetCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) Enable or disable reads from the second-level cache.voidsetCacheStoreMode(CacheStoreMode cacheStoreMode) Enable or disable writes to the second-level cache.voidsetDefaultReadOnly(boolean defaultReadOnly) Change the default for entities and proxies loaded into this session from modifiable to read-only mode, or from modifiable to read-only mode.voidsetFetchBatchSize(int batchSize) Set the maximum batch size for batch fetching associations by id in this session.voidsetFlushMode(FlushModeType flushModeType) Set the current JPA flush mode for this session.voidsetHibernateFlushMode(FlushMode flushMode) Set the current flush mode for this session.voidsetProperty(String propertyName, Object value) Set a hint.voidsetReadOnly(Object entity, boolean readOnly) Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.voidsetSubselectFetchingEnabled(boolean enabled) Enable or disable subselect fetching in this session.booleanprotected booleanshouldCloseJdbcCoordinatorOnClose(boolean isTransactionCoordinatorShared) voidCallback indicating recognition of entering into a transactional context whether that is explicitly via the HibernateTransactionAPI or via registration of Hibernate's JTA Synchronization impl with a JTA TransactiontoString()<T> TReturn an object of the specified type to allow access to a provider-specific API.Methods inherited from class org.hibernate.internal.AbstractSharedSessionContract
accessTransaction, afterObtainConnection, beforeReleaseConnection, beginTransaction, buildNamedQuery, checkMutationQuery, checkOpen, checkResultType, checkSelectionQuery, checkTransactionNeededForUpdateOperation, checkTransactionSynchStatus, createCriteriaQuery, createEntityGraph, createEntityGraph, createEntityGraph, createMutationQuery, createMutationQuery, createMutationQuery, createMutationQuery, createNamedMutationQuery, createNamedQuery, createNamedQuery, createNamedSelectionQuery, createNamedSelectionQuery, createNativeMutationQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQueryImplementor, createNativeQueryImplementor, createNativeQueryImplementor, createQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery, createSqmQueryImplementor, createSqmQueryImplementor, createSqmQueryImplementor, disableFilter, doReturningWork, doWork, enableFilter, execute, generateEntityKey, getCacheMode, getCacheTransactionSynchronization, getConfiguredJdbcBatchSize, getCriteriaBuilder, getCurrentTransaction, getDialect, getEnabledFilter, getEntityGraph, getEntityGraphs, getEntityNameResolver, getEventListenerManager, getEventMonitor, getExceptionConverter, getFactory, getInterceptor, getJdbcBatchSize, getJdbcConnectionAccess, getJdbcCoordinator, getJdbcServices, getJdbcSessionContext, getJdbcTimeZone, getJsonFormatMapper, getLobCreator, getNamedNativeQuery, getNamedNativeQuery, getNamedProcedureCall, getNamedQuery, getNativeJdbcParametersIgnored, getPreferredSqlTypeCodeForBoolean, getResultSetMappingMemento, getSessionAssociationMarkers, getSessionFactory, getSessionIdentifier, getSessionToken, getTenantIdentifier, getTenantIdentifierValue, getTransaction, getTransactionCoordinator, getTypeConfiguration, getXmlFormatMapper, interpretHql, isClosed, isConnected, isCriteriaCopyTreeEnabled, isCriteriaPlanCacheEnabled, isJoinedToTransaction, isOpenOrWaitingForAutoClose, isTransactionInProgress, joinTransaction, markForRollbackOnly, prepareForAutoClose, prepareForQueryExecution, requireCollectionPersister, requireEntityPersister, requireEntityPersister, setCacheMode, setClosed, setCriteriaCopyTreeEnabled, setCriteriaPlanCacheEnabled, setJdbcBatchSize, setNativeJdbcParametersIgnored, setUpMultitenancy, shouldAutoJoinTransaction, useStreamForLobBindingMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface jakarta.persistence.EntityManager
createNativeQuery, createNativeQuery, createNativeQuery, getCriteriaBuilder, getTransaction, isJoinedToTransaction, joinTransactionMethods inherited from interface org.hibernate.resource.jdbc.spi.JdbcSessionOwner
afterObtainConnection, beforeReleaseConnection, getEventManager, getEventMonitor, getJdbcBatchSize, getJdbcConnectionAccess, getJdbcSessionContext, getSqlExceptionHelper, getTransactionCoordinatorMethods inherited from interface org.hibernate.engine.jdbc.LobCreationContext
execute, fromContextMethods inherited from interface org.hibernate.query.QueryProducer
createMutationQuery, createNamedSelectionQuery, createNamedSelectionQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery, createSelectionQueryMethods 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, createQuery, getCacheMode, getNamedNativeQuery, getNamedNativeQuery, getNamedQueryMethods inherited from interface org.hibernate.Session
createEntityGraph, createEntityGraph, createNamedQuery, createNamedQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createQuery, getCacheMode, getEntityGraph, getEntityGraphs, setCacheModeMethods inherited from interface org.hibernate.engine.spi.SessionImplementor
callWithConnection, getSessionFactory, runWithConnectionMethods inherited from interface org.hibernate.SharedSessionContract
beginTransaction, createEntityGraph, disableFilter, doReturningWork, doWork, enableFilter, fromTransaction, getCriteriaBuilder, getEnabledFilter, getJdbcBatchSize, getNamedProcedureCall, getTenantIdentifier, getTenantIdentifierValue, getTransaction, inTransaction, isConnected, isJoinedToTransaction, joinTransaction, setJdbcBatchSizeMethods inherited from interface org.hibernate.engine.spi.SharedSessionContractImplementor
accessTransaction, asSessionImplementor, asStatelessSession, checkOpen, checkOpen, checkTransactionNeededForUpdateOperation, createEntityGraph, createEntityGraph, generateEntityKey, getCacheTransactionSynchronization, getConfiguredJdbcBatchSize, getDialect, getEntityGraph, getEventListenerManager, getExceptionConverter, getFactory, getInterceptor, getJdbcCoordinator, getJdbcServices, getNativeJdbcParametersIgnored, getSessionAssociationMarkers, getSessionFactory, getSessionIdentifier, getSessionToken, getTypeConfiguration, isClosed, isCriteriaCopyTreeEnabled, isCriteriaPlanCacheEnabled, isOpenOrWaitingForAutoClose, isSessionImplementor, isStatelessSession, isTransactionInProgress, markForRollbackOnly, prepareForQueryExecution, setCriteriaCopyTreeEnabled, setCriteriaPlanCacheEnabled, setNativeJdbcParametersIgnoredMethods inherited from interface org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options
shouldAutoJoinTransactionMethods inherited from interface org.hibernate.type.descriptor.WrapperOptions
getJdbcTimeZone, getJsonFormatMapper, getLobCreator, getPreferredSqlTypeCodeForBoolean, getXmlFormatMapper, useStreamForLobBinding
-
Constructor Details
-
SessionImpl
-
-
Method Details
-
createPersistenceContext
-
createActionQueue
-
applyQuerySettingsAndHints
- Overrides:
applyQuerySettingsAndHintsin classAbstractSharedSessionContract
-
applyLockOptionsHint
-
applyQuerySettingsAndHints
- Overrides:
applyQuerySettingsAndHintsin classAbstractSharedSessionContract
-
sessionWithOptions
Description copied from interface:SessionObtain aSessionbuilder with the ability to copy certain information from this session.- Specified by:
sessionWithOptionsin interfaceSession- Returns:
- the session builder
-
clear
public void clear()Description copied from interface:SessionCompletely clear the persistence context. Evict all loaded instances, causing every managed entity currently associated with this session to transition to the detached state, and cancel all pending insertions, updates, and deletions.Does not close open iterators or instances of
ScrollableResults.- Specified by:
clearin interfaceEntityManager- Specified by:
clearin interfaceSession
-
close
public void close()Description copied from interface:SharedSessionContractEnd the session by releasing the JDBC connection and cleaning up.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceEntityManager- Specified by:
closein interfaceSharedSessionContract- Overrides:
closein classAbstractSharedSessionContract
-
closeWithoutOpenChecks
public void closeWithoutOpenChecks() -
shouldCloseJdbcCoordinatorOnClose
protected boolean shouldCloseJdbcCoordinatorOnClose(boolean isTransactionCoordinatorShared) - Overrides:
shouldCloseJdbcCoordinatorOnClosein classAbstractSharedSessionContract
-
isAutoCloseSessionEnabled
public boolean isAutoCloseSessionEnabled()Should this session be automatically closed after the current transaction completes? -
isIdentifierRollbackEnabled
public boolean isIdentifierRollbackEnabled()- Specified by:
isIdentifierRollbackEnabledin interfaceSharedSessionContractImplementor
-
isOpen
public boolean isOpen()Description copied from interface:SharedSessionContractCheck if the session is still open.- Specified by:
isOpenin interfaceEntityManager- Specified by:
isOpenin interfaceSharedSessionContract- Overrides:
isOpenin classAbstractSharedSessionContract- Returns:
trueif it is open
-
checkSessionFactoryOpen
protected void checkSessionFactoryOpen() -
shouldAutoClose
public boolean shouldAutoClose() -
afterOperation
public void afterOperation(boolean success) Description copied from interface:SharedSessionContractImplementorCheck 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.- Specified by:
afterOperationin interfaceSharedSessionContractImplementor- Parameters:
success-trueif the operation a success
-
addEventListeners
Description copied from interface:SessionAdd one or more listeners to the Session- Specified by:
addEventListenersin interfaceSession- Parameters:
listeners- the listener(s) to add
-
cleanupOnClose
protected void cleanupOnClose()clear all the internal collections, just to help the garbage collector, does not clear anything that is needed during the afterTransactionCompletion() phase- Overrides:
cleanupOnClosein classAbstractSharedSessionContract
-
getCurrentLockMode
Description copied from interface:SessionDetermine the current lock mode held on the given managed instance associated with this session.Unlike the JPA-standard
EntityManager.getLockMode(java.lang.Object), this operation may be called when no transaction is active, in which case it should returnLockMode.NONE, indicating that no pessimistic lock is held on the given entity.- Specified by:
getCurrentLockModein interfaceSession- Parameters:
object- a persistent instance associated with this session- Returns:
- the lock mode currently held on the given entity
-
getEntityUsingInterceptor
Description copied from interface:SharedSessionContractImplementorGet the entity instance associated with the givenEntityKey, calling theInterceptorif necessary.- Specified by:
getEntityUsingInterceptorin interfaceSharedSessionContractImplementor
-
checkNoUnresolvedActionsBeforeOperation
protected void checkNoUnresolvedActionsBeforeOperation() -
checkNoUnresolvedActionsAfterOperation
protected void checkNoUnresolvedActionsAfterOperation() -
delayedAfterCompletion
public void delayedAfterCompletion()- Specified by:
delayedAfterCompletionin interfaceLoadAccessContext- Overrides:
delayedAfterCompletionin classAbstractSharedSessionContract
-
pulseTransactionCoordinator
public void pulseTransactionCoordinator()Description copied from interface:LoadAccessContextCallback to pulse the transaction coordinator- Specified by:
pulseTransactionCoordinatorin interfaceLoadAccessContext- Overrides:
pulseTransactionCoordinatorin classAbstractSharedSessionContract
-
checkOpenOrWaitingForAutoClose
public void checkOpenOrWaitingForAutoClose()Description copied from interface:LoadAccessContextCallback to check whether the session is "active"- Specified by:
checkOpenOrWaitingForAutoClosein interfaceLoadAccessContext
-
lock
Description copied from interface:SessionObtain a lock on the given managed instance associated with this session, using the given lock options.This operation cascades to associated instances if the association is mapped with
CascadeType.LOCK. -
lock
Description copied from interface:SharedSessionContractImplementorCascade the lock operation to the given child entity.- Specified by:
lockin interfaceSharedSessionContractImplementor
-
lock
Description copied from interface:SessionObtain the specified lock level on the given managed instance associated with this session. This operation may be used to:- perform a version check on an entity read from the second-level cache
by requesting
LockMode.READ, - schedule a version check at transaction commit by requesting
LockMode.OPTIMISTIC, - schedule a version increment at transaction commit by requesting
LockMode.OPTIMISTIC_FORCE_INCREMENT - upgrade to a pessimistic lock with
LockMode.PESSIMISTIC_READorLockMode.PESSIMISTIC_WRITE, or - immediately increment the version of the given instance by requesting
LockMode.PESSIMISTIC_FORCE_INCREMENT.
If the requested lock mode is already held on the given entity, this operation has no effect.
This operation cascades to associated instances if the association is mapped with
CascadeType.LOCK.The modes
LockMode.WRITEandLockMode.UPGRADE_SKIPLOCKEDare not legal arguments tolock(). - perform a version check on an entity read from the second-level cache
by requesting
-
lock
Description copied from interface:SessionObtain the specified lock level on the given managed instance associated with this session, applying any other specified options. This operation may be used to:- perform a version check on an entity read from the second-level cache
by requesting
LockMode.READ, - schedule a version check at transaction commit by requesting
LockMode.OPTIMISTIC, - schedule a version increment at transaction commit by requesting
LockMode.OPTIMISTIC_FORCE_INCREMENT - upgrade to a pessimistic lock with
LockMode.PESSIMISTIC_READorLockMode.PESSIMISTIC_WRITE, or - immediately increment the version of the given instance by requesting
LockMode.PESSIMISTIC_FORCE_INCREMENT.
If the requested lock mode is already held on the given entity, this operation has no effect.
This operation cascades to associated instances if the association is mapped with
CascadeType.LOCK.The modes
LockMode.WRITEandLockMode.UPGRADE_SKIPLOCKEDare not legal arguments tolock(). - perform a version check on an entity read from the second-level cache
by requesting
-
persist
Description copied from interface:SessionMake a transient instance persistent and mark it for later insertion in the database. This operation cascades to associated instances if the association is mapped withCascadeType.PERSIST.For entities with a
generated id,persist()ultimately results in generation of an identifier for the given instance. But this may happen asynchronously, when the session is flushed, depending on the identifier generation strategy. -
persist
Description copied from interface:SessionMake a transient instance persistent and mark it for later insertion in the database. This operation cascades to associated instances if the association is mapped withCascadeType.PERSIST.For an entity with a generated id,
persist()ultimately results in generation of an identifier for the given instance. But this may happen asynchronously, when the session is flushed, depending on the identifier generation strategy.- Specified by:
persistin interfaceEntityManager- Specified by:
persistin interfaceSession- Parameters:
object- a transient instance to be made persistent
-
persist
Description copied from interface:EventSourceCascade persist an entity instance- Specified by:
persistin interfaceEventSource
-
persistOnFlush
Description copied from interface:EventSourceCascade persist an entity instance during the flush process- Specified by:
persistOnFlushin interfaceEventSource
-
merge
Description copied from interface:SessionCopy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped withCascadeType.MERGE. -
merge
Description copied from interface:SessionCopy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped withCascadeType.MERGE. -
merge
public <T> T merge(T object) Description copied from interface:SessionCopy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped withCascadeType.MERGE.- Specified by:
mergein interfaceEntityManager- Specified by:
mergein interfaceSession- Parameters:
object- a detached instance with state to be copied- Returns:
- an updated persistent instance
-
merge
Description copied from interface:EventSourceCascade merge an entity instance- Specified by:
mergein interfaceEventSource
-
delete
public void delete(String entityName, Object object, boolean isCascadeDeleteEnabled, DeleteContext transientEntities) Description copied from interface:EventSourceCascade delete an entity instance- Specified by:
deletein interfaceEventSource
-
removeOrphanBeforeUpdates
Description copied from interface:EventSourceA specialized type of deletion for orphan removal that must occur prior to queued inserts and updates.- Specified by:
removeOrphanBeforeUpdatesin interfaceEventSource
-
load
Description copied from interface:SessionRead the persistent state associated with the given identifier into the given transient instance. -
findMultiple
Description copied from interface:SessionReturn the persistent instances of the given entity class with the given identifiers as a list. The position of an instance in the returned list matches the position of its identifier in the given list of identifiers, and the returned list contains a null value if there is no persistent instance matching a given identifier. If an instance is already associated with the session, that instance is returned. This method never returns an uninitialized instance.Every object returned by
findMultiple()is either an unproxied instance of the given entity class, or a fully-fetched proxy object.This method accepts
BatchSizeas an option, allowing control over the number of records retrieved in a single database request. The performance impact of setting a batch size depends on whether a SQL array may be used to pass the list of identifiers to the database:- for databases which support standard SQL arrays, a smaller batch size might be extremely inefficient compared to a very large batch size or no batching at all, but
- on the other hand, for databases with no SQL array type, a large batch size results in long SQL statements with many JDBC parameters.
For more advanced cases, use
Session.byMultipleIds(Class), which returns an instance ofMultiIdentifierLoadAccess.- Specified by:
findMultiplein interfaceSession- Parameters:
entityType- the entity typeids- the list of identifiersoptions- options, if any- Returns:
- an ordered list of persistent instances, with null elements representing missing entities, whose positions in the list match the positions of their ids in the given list of identifiers
- See Also:
-
findMultiple
Description copied from interface:SessionReturn the persistent instances of the root entity of the givenEntityGraphwith the given identifiers as a list, fetching the associations specified by the graph, which is interpreted as a load graph. The position of an instance in the returned list matches the position of its identifier in the given list of identifiers, and the returned list contains a null value if there is no persistent instance matching a given identifier. If an instance is already associated with the session, that instance is returned. This method never returns an uninitialized instance.Every object returned by
findMultiple()is either an unproxied instance of the given entity class, or a fully-fetched proxy object.This method accepts
BatchSizeas an option, allowing control over the number of records retrieved in a single database request. The performance impact of setting a batch size depends on whether a SQL array may be used to pass the list of identifiers to the database:- for databases which support standard SQL arrays, a smaller batch size might be extremely inefficient compared to a very large batch size or no batching at all, but
- on the other hand, for databases with no SQL array type, a large batch size results in long SQL statements with many JDBC parameters.
For more advanced cases, use
Session.byMultipleIds(Class), which returns an instance ofMultiIdentifierLoadAccess.- Specified by:
findMultiplein interfaceSession- Parameters:
entityGraph- the entity graph interpreted as a load graphids- the list of identifiersoptions- options, if any- Returns:
- an ordered list of persistent instances, with null elements representing missing entities, whose positions in the list match the positions of their ids in the given list of identifiers
- See Also:
-
get
Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance.The object returned by
get()orfind()is either an unproxied instance of the given entity class, or a fully-fetched proxy object.This operation requests
LockMode.NONE, that is, no lock, allowing the object to be retrieved from the cache without the cost of database access. However, if it is necessary to read the state from the database, the object will be returned with the lock modeLockMode.READ.To bypass the second-level cache, and ensure that the state is read from the database, either:
- call
Session.get(Class, Object, LockMode)with the explicit lock modeLockMode.READ, or - set the cache mode to
CacheMode.IGNOREbefore calling this method.
- call
-
get
Description copied from interface:SessionReturn the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. -
immediateLoad
Load the data for the object with the specified id into a newly created object. This is only called when lazily initializing a proxy. Do NOT return a proxy.- Specified by:
immediateLoadin interfaceSharedSessionContractImplementor
-
internalLoad
Description copied from interface:SharedSessionContractImplementorObtain 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, anullvalue is returned.
When
eager = true, the object is eagerly fetched from the database.- Specified by:
internalLoadin interfaceSharedSessionContractImplementor
- When
-
internalLoadType
-
loadFromSecondLevelCache
public Object loadFromSecondLevelCache(EntityPersister persister, EntityKey entityKey, Object instanceToLoad, LockMode lockMode) Description copied from interface:SharedSessionContractImplementorAttempts to load the entity from the second-level cache.- Specified by:
loadFromSecondLevelCachein interfaceSharedSessionContractImplementor- Parameters:
persister- The persister for the entity being requested for loadentityKey- The entity keyinstanceToLoad- The instance that is being initialized, or nulllockMode- The lock mode- Returns:
- The entity from the second-level cache, or null.
-
makePostLoadEvent
Helper to avoid creating many new instances ofPostLoadEvent. It's an allocation hot spot. -
makeLoadEvent
protected LoadEvent makeLoadEvent(String entityName, Object id, Boolean readOnly, LockOptions lockOptions) Helper to avoid creating many new instances ofLoadEvent. It's an allocation hot spot. -
makeLoadEvent
protected LoadEvent makeLoadEvent(String entityName, Object id, Boolean readOnly, boolean isAssociationFetch) Helper to avoid creating many new instances ofLoadEvent. It's an allocation hot spot. -
releasePostLoadEvent
-
releaseLoadEvent
-
get
Deprecated.Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
get
Deprecated.Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
get
Deprecated.Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
get
Deprecated.Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
byId
Description copied from interface:SessionCreate anIdentifierLoadAccessinstance to retrieve an instance of the named entity type by its primary key.- Specified by:
byIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
IdentifierLoadAccessfor executing the lookup
-
byId
Description copied from interface:SessionCreate anIdentifierLoadAccessinstance to retrieve an instance of the given entity type by its primary key.- Specified by:
byIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
IdentifierLoadAccessfor executing the lookup
-
byMultipleIds
Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the given entity type by their primary key values, using batching.- Specified by:
byMultipleIdsin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
MultiIdentifierLoadAccessfor executing the lookup - See Also:
-
byMultipleIds
Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the named entity type by their primary key values, using batching.- Specified by:
byMultipleIdsin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
MultiIdentifierLoadAccessfor executing the lookup
-
byNaturalId
Description copied from interface:SessionCreate aNaturalIdLoadAccessinstance to retrieve an instance of the named entity type by its natural id, which may be a composite natural id. The entity must have at least one attribute annotatedNaturalId.- Specified by:
byNaturalIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
NaturalIdLoadAccessfor executing the lookup
-
byNaturalId
Description copied from interface:SessionCreate aNaturalIdLoadAccessinstance to retrieve an instance of the given entity type by its natural id, which may be a composite natural id. The entity must have at least one attribute annotatedNaturalId.- Specified by:
byNaturalIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
NaturalIdLoadAccessfor executing the lookup
-
bySimpleNaturalId
Description copied from interface:SessionCreate aSimpleNaturalIdLoadAccessinstance to retrieve an instance of the named entity type by its natural id, which must be a simple (non-composite) value. The entity must have exactly one attribute annotatedNaturalId.- Specified by:
bySimpleNaturalIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
SimpleNaturalIdLoadAccessfor executing the lookup
-
bySimpleNaturalId
Description copied from interface:SessionCreate aSimpleNaturalIdLoadAccessinstance to retrieve an instance of the given entity type by its natural id, which must be a simple (non-composite) value. The entity must have exactly one attribute annotatedNaturalId.- Specified by:
bySimpleNaturalIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
SimpleNaturalIdLoadAccessfor executing the lookup
-
byMultipleNaturalId
Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the given entity type by their by natural id values, using batching.- Specified by:
byMultipleNaturalIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
NaturalIdMultiLoadAccessfor executing the lookup
-
byMultipleNaturalId
Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the named entity type by their by natural id values, using batching.- Specified by:
byMultipleNaturalIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
NaturalIdMultiLoadAccessfor executing the lookup
-
load
public Object load(LoadEventListener.LoadType loadType, Object id, String entityName, LockOptions lockOptions, Boolean readOnly) Description copied from interface:LoadAccessContextEfficiently fire aLoadEventwith the given type and return the resulting entity instance or proxy.- Specified by:
loadin interfaceLoadAccessContext
-
refresh
Description copied from interface:SessionReread the state of the given managed instance associated with this session from the underlying database. This may be useful:- when a database trigger alters the object state upon insert or update,
- after executing any HQL update or delete statement,
- after executing a native SQL statement, or
- after inserting a
BloborClob.
This operation cascades to associated instances if the association is mapped with
CascadeType.REFRESH.This operation requests
LockMode.READ. To obtain a stronger lock, callEntityManager.refresh(Object, RefreshOption...), passing the appropriateLockModeas an option.- Specified by:
refreshin interfaceEntityManager- Specified by:
refreshin interfaceSession- Parameters:
object- a persistent instance associated with this session
-
refresh
Description copied from interface:SessionReread the state of the given managed instance from the underlying database, obtaining the givenLockMode. -
refresh
Description copied from interface:EventSourceCascade refresh an entity instance- Specified by:
refreshin interfaceEventSource
-
replicate
Description copied from interface:SessionPersist the state of the given detached instance, reusing the current identifier value. This operation cascades to associated instances if the association is mapped withCascadeType.REPLICATE. -
replicate
Description copied from interface:SessionPersist the state of the given detached instance, reusing the current identifier value. This operation cascades to associated instances if the association is mapped withCascadeType.REPLICATE. -
evict
remove any hard references to the entity that are held by the infrastructure (references held by application or other persistent instances are okay) -
autoFlushIfRequired
Description copied from interface:SharedSessionContractImplementordetect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush- Specified by:
autoFlushIfRequiredin interfaceSharedSessionContractImplementor- Parameters:
querySpaces- the tables named in the query.- Returns:
- true if flush is required, false otherwise.
-
autoFlushIfRequired
Description copied from interface:SharedSessionContractImplementordetect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush- Specified by:
autoFlushIfRequiredin interfaceSharedSessionContractImplementor- Parameters:
querySpaces- the tables named in the query.skipPreFlush- seeAutoFlushEvent.isSkipPreFlush()- Returns:
- true if flush is required, false otherwise.
-
autoPreFlush
public void autoPreFlush()- Specified by:
autoPreFlushin interfaceSharedSessionContractImplementor
-
isDirty
public boolean isDirty()Description copied from interface:SessionDoes this session contain any changes which must be synchronized with the database? In other words, would any DML operations be executed if we flushed this session? -
flush
public void flush()Description copied from interface:SharedSessionContractImplementorFlush this session.- Specified by:
flushin interfaceEntityManager- Specified by:
flushin interfaceSession- Specified by:
flushin interfaceSharedSessionContractImplementor
-
setHibernateFlushMode
Description copied from interface:SessionSet the current flush mode for this session.Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory. The current flush mode determines when the session is automatically flushed.
The default flush mode is sometimes unnecessarily aggressive. For a logically "read only" session, it's reasonable to set the session's flush mode to
FlushMode.MANUALat the start of the session in order to avoid some unnecessary work.Note that
FlushModedefines more options thanFlushModeType.- Specified by:
setHibernateFlushModein interfaceSession- Parameters:
flushMode- the newFlushMode
-
getHibernateFlushMode
Description copied from interface:SharedSessionContractImplementorGet the currentFlushModefor this session.- Specified by:
getHibernateFlushModein interfaceQueryProducerImplementor- Specified by:
getHibernateFlushModein interfaceSession- Specified by:
getHibernateFlushModein interfaceSharedSessionContractImplementor- Returns:
- The flush mode
-
getFlushMode
Description copied from interface:SessionGet the current JPA flush mode for this session.- Specified by:
getFlushModein interfaceEntityManager- Specified by:
getFlushModein interfaceSession- Returns:
- the
FlushModeTypecurrently in effect - See Also:
-
setFlushMode
Description copied from interface:SessionSet the current JPA flush mode for this session.Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory. The current flush mode determines when the session is automatically flushed.
- Specified by:
setFlushModein interfaceEntityManager- Specified by:
setFlushModein interfaceSession- Parameters:
flushModeType- the newFlushModeType- See Also:
-
forceFlush
Description copied from interface:SessionImplementorInitiate a flush to force deletion of a re-persisted entity.- Specified by:
forceFlushin interfaceEventSource- Specified by:
forceFlushin interfaceSessionImplementor
-
forceFlush
Description copied from interface:SessionImplementorInitiate a flush to force deletion of a re-persisted entity.- Specified by:
forceFlushin interfaceEventSource- Specified by:
forceFlushin interfaceSessionImplementor
-
instantiate
Deprecated.Description copied from interface:SharedSessionContractImplementorInstantiate the entity class, initializing with the given identifier.- Specified by:
instantiatein interfaceSharedSessionContractImplementor
-
instantiate
give the interceptor an opportunity to override the default instantiation- Specified by:
instantiatein interfaceEventSource- Specified by:
instantiatein interfaceSessionImplementor- Specified by:
instantiatein interfaceSharedSessionContractImplementor
-
getEntityPersister
Description copied from interface:SharedSessionContractImplementorGet theEntityPersisterfor the given entity instance.- Specified by:
getEntityPersisterin interfaceSharedSessionContractImplementor- Parameters:
entityName- optional entity nameobject- the entity instance
-
getIdentifier
Description copied from interface:SessionReturn the identifier value of the given entity associated with this session. An exception is thrown if the given entity instance is transient or detached in relation to this session.- Specified by:
getIdentifierin interfaceSession- Parameters:
object- a persistent instance associated with this session- Returns:
- the identifier
-
getContextEntityIdentifier
Get the id value for an object that is actually associated with the session. This is a bit stricter thanForeignKeys.getEntityIdentifierIfNotUnsaved(java.lang.String, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor).- Specified by:
getContextEntityIdentifierin interfaceSharedSessionContractImplementor
-
contains
- Specified by:
containsin interfaceEntityManager
-
contains
Description copied from interface:SessionDetermine if the given entity is associated with this session. -
createStoredProcedureCall
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure.- Specified by:
createStoredProcedureCallin interfaceSharedSessionContract- Overrides:
createStoredProcedureCallin classAbstractSharedSessionContract- Parameters:
procedureName- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureCall
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings.- Specified by:
createStoredProcedureCallin interfaceSharedSessionContract- Overrides:
createStoredProcedureCallin classAbstractSharedSessionContract- Parameters:
procedureName- The name of the procedure.resultSetMappings- The explicit result set mapping(s) to use for mapping the results- Returns:
- The representation of the procedure call.
-
createStoredProcedureCall
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings. Each given class is considered a "root return".- Specified by:
createStoredProcedureCallin interfaceSharedSessionContract- Overrides:
createStoredProcedureCallin classAbstractSharedSessionContract- Parameters:
procedureName- The name of the procedure.resultClasses- The entity(s) to map the result on to.- Returns:
- The representation of the procedure call.
-
createQuery
- Specified by:
createQueryin interfaceEntityManager- Specified by:
createQueryin interfaceSessionImplementor
-
initializeCollection
Description copied from interface:SharedSessionContractImplementorInitialize the given collection (if not already initialized).- Specified by:
initializeCollectionin interfaceSharedSessionContractImplementor
-
bestGuessEntityName
Description copied from interface:SharedSessionContractImplementorObtain 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.- Specified by:
bestGuessEntityNamein interfaceSharedSessionContractImplementor
-
bestGuessEntityName
Description copied from interface:SharedSessionContractImplementorObtain 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.- Specified by:
bestGuessEntityNamein interfaceSharedSessionContractImplementor
-
getEntityName
Description copied from interface:SessionReturn the entity name for the given persistent entity.If the given entity is an uninitialized proxy, the proxy is initialized by side effect.
- Specified by:
getEntityNamein interfaceSession- Parameters:
object- a persistent entity associated with this session- Returns:
- the entity name
-
getReference
public <T> T getReference(T object) Description copied from interface:SessionReturn a reference to the persistent instance with the same identity as the given instance, which might be detached, making the assumption that the instance is still persistent in the database. This method never results in access to the underlying data store, and thus might return a proxy that is initialized on-demand, when a non-identifier method is accessed.- Specified by:
getReferencein interfaceEntityManager- Specified by:
getReferencein interfaceSession- Parameters:
object- a detached persistent instance- Returns:
- the persistent instance or proxy
-
guessEntityName
Description copied from interface:SharedSessionContractImplementorObtain an estimate of the entity name of the given entity instance, which is not involved in an association, using only theEntityNameResolver.- Specified by:
guessEntityNamein interfaceSharedSessionContractImplementor
-
cancelQuery
public void cancelQuery()Description copied from interface:SessionCancel the execution of the current query.This is the sole method on session which may be safely called from another thread.
- Specified by:
cancelQueryin interfaceSession
-
toString
-
getActionQueue
Description copied from interface:SessionImplementorGet theActionQueueassociated with this session.- Specified by:
getActionQueuein interfaceEventSource- Specified by:
getActionQueuein interfaceSessionImplementor
-
registerProcess
Description copied from interface:SharedSessionContractImplementorRegisters the given process for execution after transaction completion.- Specified by:
registerProcessin interfaceSharedSessionContractImplementor- Parameters:
process- The process to register
-
getPersistenceContext
Description copied from interface:SharedSessionContractImplementorGet the persistence context for this session.See
SharedSessionContractImplementor.getPersistenceContextInternal()for a faster alternative.- Specified by:
getPersistenceContextin interfaceSharedSessionContractImplementor
-
getPersistenceContextInternal
Description copied from interface:SharedSessionContractImplementorSimilar toSharedSessionContractImplementor.getPersistenceContext(), 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.
- Specified by:
getPersistenceContextInternalin interfaceSharedSessionContractImplementor- Returns:
- the
PersistenceContextassociated to this session.
-
getStatistics
Description copied from interface:SessionGet the statistics for this session.- Specified by:
getStatisticsin interfaceSession- Returns:
- the session statistics being collected for this session
-
isEventSource
public boolean isEventSource()Description copied from interface:SharedSessionContractImplementorDetermines if this session implementsEventSource.Only stateful session are sources of events. If this object is a stateless session, this method return
false.- Specified by:
isEventSourcein interfaceSharedSessionContractImplementor
-
asEventSource
Description copied from interface:SharedSessionContractImplementorCast this session toEventSourceif possible.Only stateful session are sources of events. If this object is a stateless session, this method throws.
- Specified by:
asEventSourcein interfaceSharedSessionContractImplementor
-
isDefaultReadOnly
public boolean isDefaultReadOnly()Description copied from interface:SharedSessionContractImplementorAre entities and proxies loaded by this session read-only by default?- Specified by:
isDefaultReadOnlyin interfaceSession- Specified by:
isDefaultReadOnlyin interfaceSharedSessionContractImplementor- Returns:
true, loaded entities/proxies will be made read-only by default;false, loaded entities/proxies will be made modifiable by default.- See Also:
-
setDefaultReadOnly
public void setDefaultReadOnly(boolean defaultReadOnly) Description copied from interface:SessionChange the default for entities and proxies loaded into this session from modifiable to read-only mode, or from modifiable to read-only mode.Read-only entities are not dirty-checked and snapshots of persistent state are not maintained. Read-only entities can be modified, but changes are not persisted.
When a proxy is initialized, the loaded entity will have the same read-only/modifiable setting as the uninitialized proxy has, regardless of the session's current setting.
To change the read-only/modifiable setting for a particular entity or proxy that already belongs to this session use
Session.setReadOnly(Object, boolean).To override this session's read-only/modifiable setting for all entities and proxies loaded by a certain
QueryuseQuery.setReadOnly(boolean).- Specified by:
setDefaultReadOnlyin interfaceSession- Parameters:
defaultReadOnly-true, the default for loaded entities/proxies is read-only;false, the default for loaded entities/proxies is modifiable- See Also:
-
isReadOnly
Description copied from interface:SessionIs the specified entity or proxy read-only?To get the default read-only/modifiable setting used for entities and proxies that are loaded into the session use
Session.isDefaultReadOnly()- Specified by:
isReadOnlyin interfaceSession- Parameters:
entityOrProxy- an entity or proxy- Returns:
trueif the entity or proxy is read-only,falseif the entity or proxy is modifiable.- See Also:
-
setReadOnly
Description copied from interface:SessionSet an unmodified persistent object to read-only mode, or a read-only object to modifiable mode. In read-only mode, no snapshot is maintained, the instance is never dirty checked, and changes are not persisted.If the entity or proxy already has the specified read-only/modifiable setting, then this method does nothing.
To set the default read-only/modifiable setting used for all entities and proxies that are loaded into the session use
Session.setDefaultReadOnly(boolean).To override this session's read-only/modifiable setting for entities and proxies loaded by a
QueryuseQuery.setReadOnly(boolean)- Specified by:
setReadOnlyin interfaceSession- Parameters:
entity- an entity or proxyreadOnly-trueif the entity or proxy should be made read-only;falseif the entity or proxy should be made modifiable- See Also:
-
getCacheStoreMode
Description copied from interface:SessionThe JPA-definedCacheStoreMode.- Specified by:
getCacheStoreModein interfaceEntityManager- Specified by:
getCacheStoreModein interfaceSession- See Also:
-
getCacheRetrieveMode
Description copied from interface:SessionThe JPA-definedCacheRetrieveMode.- Specified by:
getCacheRetrieveModein interfaceEntityManager- Specified by:
getCacheRetrieveModein interfaceSession- See Also:
-
setCacheStoreMode
Description copied from interface:SessionEnable or disable writes to the second-level cache.- Specified by:
setCacheStoreModein interfaceEntityManager- Specified by:
setCacheStoreModein interfaceSession- Parameters:
cacheStoreMode- a JPA-definedCacheStoreMode- See Also:
-
setCacheRetrieveMode
Description copied from interface:SessionEnable or disable reads from the second-level cache.- Specified by:
setCacheRetrieveModein interfaceEntityManager- Specified by:
setCacheRetrieveModein interfaceSession- Parameters:
cacheRetrieveMode- a JPA-definedCacheRetrieveMode- See Also:
-
afterScrollOperation
public void afterScrollOperation()Description copied from interface:SharedSessionContractImplementorCalled 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.- Specified by:
afterScrollOperationin interfaceSharedSessionContractImplementor
-
getLoadQueryInfluencers
Description copied from interface:SharedSessionContractImplementorGet theLoadQueryInfluencersassociated with this session.- Specified by:
getLoadQueryInfluencersin interfaceSharedSessionContractImplementor- Returns:
- the
LoadQueryInfluencersassociated with this session; should never be null.
-
isFetchProfileEnabled
Description copied from interface:SessionIs thefetch profilewith the given name enabled in this session?- Specified by:
isFetchProfileEnabledin interfaceSession- Parameters:
name- the name of the profile- Returns:
- True if fetch profile is enabled; false if not.
- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
enableFetchProfile
Description copied from interface:SessionEnable thefetch profilewith the given name in this session. If the requested fetch profile is already enabled, the call has no effect.- Specified by:
enableFetchProfilein interfaceSession- Parameters:
name- the name of the fetch profile to be enabled- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
disableFetchProfile
Description copied from interface:SessionDisable thefetch profilewith the given name in this session. If the requested fetch profile is not currently enabled, the call has no effect.- Specified by:
disableFetchProfilein interfaceSession- Parameters:
name- the name of the fetch profile to be disabled- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
setSubselectFetchingEnabled
public void setSubselectFetchingEnabled(boolean enabled) Description copied from interface:SessionEnable or disable subselect fetching in this session. Override the factory-level default controlled by the configuration property "hibernate.use_subselect_fetch".- Specified by:
setSubselectFetchingEnabledin interfaceSession- Parameters:
enabled-trueto enable subselect fetching- See Also:
-
isSubselectFetchingEnabled
public boolean isSubselectFetchingEnabled()Description copied from interface:SessionDetermine if subselect fetching is enabled in this session.- Specified by:
isSubselectFetchingEnabledin interfaceSession- Returns:
trueis subselect fetching is enabled
-
setFetchBatchSize
public void setFetchBatchSize(int batchSize) Description copied from interface:SessionSet the maximum batch size for batch fetching associations by id in this session. Override the factory-level default controlled by the configuration property "hibernate.default_batch_fetch_size".- If
batchSize>1, then batch fetching is enabled. - If
batchSize<0, the batch size is inherited from the factory-level setting. - Otherwise, batch fetching is disabled.
- Specified by:
setFetchBatchSizein interfaceSession- Parameters:
batchSize- the maximum batch size for batch fetching- See Also:
- If
-
getFetchBatchSize
public int getFetchBatchSize()Description copied from interface:SessionGet the maximum batch size for batch fetching associations by id in this session.- Specified by:
getFetchBatchSizein interfaceSession
-
getLobHelper
Description copied from interface:Session- Specified by:
getLobHelperin interfaceSession- Returns:
- an instance of
LobHelper
-
beforeTransactionCompletion
public void beforeTransactionCompletion()Description copied from interface:JdbcSessionOwnerA before-completion callback to the owner.- Specified by:
beforeTransactionCompletionin interfaceJdbcSessionOwner- Overrides:
beforeTransactionCompletionin classAbstractSharedSessionContract
-
afterTransactionCompletion
public void afterTransactionCompletion(boolean successful, boolean delayed) Description copied from interface:JdbcSessionOwnerAn after-completion callback to the owner.- Specified by:
afterTransactionCompletionin interfaceJdbcSessionOwner- Overrides:
afterTransactionCompletionin classAbstractSharedSessionContract- Parameters:
successful- Was the transaction successful?delayed- Is this a delayed after transaction completion call (aka after a timeout)?
-
startTransactionBoundary
public void startTransactionBoundary()Description copied from interface:JdbcSessionOwnerCallback indicating recognition of entering into a transactional context whether that is explicitly via the HibernateTransactionAPI or via registration of Hibernate's JTA Synchronization impl with a JTA Transaction- Specified by:
startTransactionBoundaryin interfaceJdbcSessionOwner- Overrides:
startTransactionBoundaryin classAbstractSharedSessionContract
-
afterTransactionBegin
public void afterTransactionBegin()Description copied from interface:JdbcSessionOwnerAn after-begin callback from the coordinator to its owner.- Specified by:
afterTransactionBeginin interfaceJdbcSessionOwner
-
flushBeforeTransactionCompletion
public void flushBeforeTransactionCompletion()- Specified by:
flushBeforeTransactionCompletionin interfaceJdbcSessionOwner
-
getSession
Description copied from interface:SharedSessionContractImplementorReturns this object, fulfilling the contract ofWrapperOptions.- Specified by:
getSessionin interfaceLoadAccessContext- Specified by:
getSessionin interfaceSessionImplementor- Specified by:
getSessionin interfaceSharedSessionContractImplementor- Specified by:
getSessionin interfaceWrapperOptions
-
remove
Description copied from interface:SessionMark a persistence instance associated with this session for removal from the underlying database. Ths operation cascades to associated instances if the association is mappedCascadeType.REMOVE.Except when operating in fully JPA-compliant mode, this operation does, contrary to the JPA specification, accept a detached entity instance.
- Specified by:
removein interfaceEntityManager- Specified by:
removein interfaceSession- Parameters:
entity- the managed persistent instance to remove, or a detached instance unless operating in fully JPA-compliant mode
-
find
Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance.The object returned by
get()orfind()is either an unproxied instance of the given entity class, or a fully-fetched proxy object.This operation requests
LockMode.NONE, that is, no lock, allowing the object to be retrieved from the cache without the cost of database access. However, if it is necessary to read the state from the database, the object will be returned with the lock modeLockMode.READ.To bypass the second-level cache, and ensure that the state of the requested instance is read directly from the database, either:
- call
EntityManager.find(Class, Object, FindOption...), passingCacheRetrieveMode.BYPASSas an option, - call
EntityManager.find(Class, Object, FindOption...)with the explicit lock modeLockMode.READ, or - set the cache mode to
CacheRetrieveMode.BYPASSbefore calling this method.
- Specified by:
findin interfaceEntityManager- Specified by:
findin interfaceSession- Parameters:
entityClass- the entity typeprimaryKey- an identifier- Returns:
- a fully-fetched persistent instance or null
- call
-
find
- Specified by:
findin interfaceEntityManager
-
find
- Specified by:
findin interfaceEntityManager
-
find
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> properties) - Specified by:
findin interfaceEntityManager
-
logIgnoringEntityNotFound
-
find
- Specified by:
findin interfaceEntityManager
-
find
- Specified by:
findin interfaceEntityManager
-
checkTransactionNeededForLock
-
readOnlyHint
-
determineAppropriateLocalCacheMode
-
find
Description copied from interface:SessionReturn the persistent instance of the named entity type with the given identifier, or null if there is no such persistent instance. Differs from Session.find(Class, Object) in that this form accepts the entity name of a dynamic entity. -
find
Description copied from interface:SessionReturn the persistent instance of the named entity type with the given identifier using the specified options, or null if there is no such persistent instance. Differs from EntityManager.find(Class, Object, FindOption...) in that this form accepts the entity name of a dynamic entity. -
getReference
Description copied from interface:SessionReturn a reference to the persistent instance with the given class and identifier, making the assumption that the instance is still persistent in the database. This method never results in access to the underlying data store, and thus might return a proxy that is initialized on-demand, when a non-identifier method is accessed.Note that
Hibernate.createDetachedProxy(SessionFactory, Class, Object)may be used to obtain a detached reference.It's sometimes necessary to narrow a reference returned by
getReference()to a subtype of the given entity type. A direct Java typecast should never be used in this situation. Instead, the methodHibernate.unproxy(Object, Class)is the recommended way to narrow the type of a proxy object. Alternatively, a new reference may be obtained by simply callinggetReference()again, passing the subtype. Either way, the narrowed reference will usually not be identical to the original reference, when the references are compared using the==operator.- Specified by:
getReferencein interfaceEntityManager- Specified by:
getReferencein interfaceSession- Parameters:
entityClass- the entity typeid- the identifier of a persistent instance that exists in the database- Returns:
- the persistent instance or proxy
-
getReference
Description copied from interface:SessionReturn a reference to the persistent instance of the given named entity with the given identifier, making the assumption that the instance is still persistent in the database. This method never results in access to the underlying data store, and thus might return a proxy that is initialized on-demand, when a non-identifier method is accessed.- Specified by:
getReferencein interfaceSession- Parameters:
entityName- the entity nameid- the identifier of a persistent instance that exists in the database- Returns:
- the persistent instance or proxy
-
lock
- Specified by:
lockin interfaceEntityManager
-
lock
- Specified by:
lockin interfaceEntityManager
-
lock
- Specified by:
lockin interfaceEntityManager
-
refresh
- Specified by:
refreshin interfaceEntityManager
-
refresh
- Specified by:
refreshin interfaceEntityManager
-
refresh
- Specified by:
refreshin interfaceEntityManager
-
refresh
- Specified by:
refreshin interfaceEntityManager
-
detach
Description copied from interface:SessionRemove this instance from the session cache. Changes to the instance will not be synchronized with the database. This operation cascades to associated instances if the association is mapped withCascadeType.DETACH.- Specified by:
detachin interfaceEntityManager- Specified by:
detachin interfaceSession- Parameters:
entity- the managed instance to detach
-
getLockMode
- Specified by:
getLockModein interfaceEntityManager
-
setProperty
Description copied from interface:SessionSet a hint. The hints understood by Hibernate are enumerated byAvailableHints.- Specified by:
setPropertyin interfaceEntityManager- Specified by:
setPropertyin interfaceSession- See Also:
-
getProperties
- Specified by:
getPropertiesin interfaceEntityManager
-
createNamedStoredProcedureQuery
Description copied from interface:SharedSessionContractObtain aProcedureCallbased on a named template- Specified by:
createNamedStoredProcedureQueryin interfaceEntityManager- Specified by:
createNamedStoredProcedureQueryin interfaceSharedSessionContract- Overrides:
createNamedStoredProcedureQueryin classAbstractSharedSessionContract- Parameters:
name- The name given to the template- Returns:
- The ProcedureCall
- See Also:
-
createStoredProcedureQuery
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure.- Specified by:
createStoredProcedureQueryin interfaceEntityManager- Specified by:
createStoredProcedureQueryin interfaceSharedSessionContract- Overrides:
createStoredProcedureQueryin classAbstractSharedSessionContract- Parameters:
procedureName- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureQuery
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings. Each given class is considered a "root return".- Specified by:
createStoredProcedureQueryin interfaceEntityManager- Specified by:
createStoredProcedureQueryin interfaceSharedSessionContract- Overrides:
createStoredProcedureQueryin classAbstractSharedSessionContract- Parameters:
procedureName- The name of the procedure.resultClasses- The entity(s) to map the result on to.- Returns:
- The representation of the procedure call.
-
createStoredProcedureQuery
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings.- Specified by:
createStoredProcedureQueryin interfaceEntityManager- Specified by:
createStoredProcedureQueryin interfaceSharedSessionContract- Overrides:
createStoredProcedureQueryin classAbstractSharedSessionContract- Parameters:
procedureName- The name of the procedure.resultSetMappings- The explicit result set mapping(s) to use for mapping the results- Returns:
- The representation of the procedure call.
-
unwrap
Description copied from interface:SharedSessionContractReturn an object of the specified type to allow access to a provider-specific API.- Specified by:
unwrapin interfaceEntityManager- Specified by:
unwrapin interfaceSession- Specified by:
unwrapin interfaceSharedSessionContract- Parameters:
type- the class of the object to be returned. This is usually either the underlying class implementingSharedSessionContractor an interface it implements.- Returns:
- an instance of the specified class
-
getDelegate
- Specified by:
getDelegatein interfaceEntityManager
-
getEntityManagerFactory
- Specified by:
getEntityManagerFactoryin interfaceEntityManager
-
getMetamodel
- Specified by:
getMetamodelin interfaceEntityManager
-
getManagedEntities
Description copied from interface:SessionObtain the collection of all managed entities which belong to this persistence context.- Specified by:
getManagedEntitiesin interfaceSession
-
getManagedEntities
Description copied from interface:SessionObtain a collection of all managed instances of the entity type with the given entity name which belong to this persistence context.- Specified by:
getManagedEntitiesin interfaceSession
-
getManagedEntities
Description copied from interface:SessionObtain a collection of all managed entities of the given type which belong to this persistence context. This operation is not polymorphic, and does not return instances of subtypes of the given entity type.- Specified by:
getManagedEntitiesin interfaceSession
-
getManagedEntities
Description copied from interface:SessionObtain a collection of all managed entities of the given type which belong to this persistence context. This operation is not polymorphic, and does not return instances of subtypes of the given entity type.- Specified by:
getManagedEntitiesin interfaceSession
-
getReadOnlyFromLoadQueryInfluencers
-