org.hibernate.Session and
org.hibernate.StatelessSession as used by other parts of Hibernate,
including implementors of org.hibernate.type.Type , EntityPersister,
and org.hibernate.persister.collection.CollectionPersister .
The Session, via this interface and SharedSessionContractImplementor,
implements:
JdbcSessionOwner, and so the session also acts as the orchestrator
of a "JDBC session", and may be used to construct a JdbcCoordinator.
Options, allowing the session to control the creation of the
TransactionCoordinator delegate when it is passed as an argument to
org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder#buildTransactionCoordinator
LobCreationContext, and so the session may act as the context for
JDBC LOB instance creation.
WrapperOptions, and so the session may influence the process of binding
and extracting values to and from JDBC, which is performed by implementors of
org.hibernate.type.descriptor.jdbc.JdbcType .
| Modifier and Type | Method and Description |
|---|---|
| public Transaction | Returns: theTransactionRetrieves the current |
| public void | afterOperation(boolean
true if the operation a successCheck 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. |
| public void | afterScrollOperation()
Called after each operation on a |
| public default EventSource | |
| public default SessionImplementor | |
| public default StatelessSession | |
| public boolean | Returns: true if flush is required, false otherwise.the tables named in the query. querySpaces)detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush |
| public String | bestGuessEntityName(Object object)
Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session. |
| public default String | bestGuessEntityName(Object object, EntityEntry entry)
Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session. |
| public default void | checkOpen()
Check whether the session is open, and if not:
|
| public void | checkOpen(boolean markForRollbackIfClosed)
Check whether the session is open, and if not:
|
| public default void | checkTransactionNeededForUpdateOperation(String
the message to use for the exceptionMessage)TransactionRequiredExceptionCheck if an active |
| public void | |
| public EntityKey | Returns: The entity keyThe entity id id, EntityPersister The entity persister persister)Instantiate an |
| public CacheMode | getCacheMode()
Redeclares org. CacheMode for this session.
|
| public CacheTransactionSynchronization | getCacheTransactionSynchronization()
The current |
| public default Integer | Returns: the session-level JDBC batch size is set, or the factory-level setting otherwiseGet the currently configured JDBC batch size, which might have been specified at either the session or factory level. |
| public Object | getContextEntityIdentifier(Object object)
Return the identifier of the persistent object, or null if it is not associated with this session. |
| public EntityPersister | getEntityPersister(@Nullable String
optional entity name entityName, Object the entity instance object)Get the |
| public Object | getEntityUsingInterceptor(EntityKey key)
Get the entity instance associated with the given |
| public SessionEventListenerManager | |
| public ExceptionConverter | Returns: the ExceptionConverter for this Session.Obtain an |
| public SessionFactoryImplementor | getFactory()
Redeclares org.
Deprecated
as a consequence of
Obtain the factory which created this session.
SessionFactoryImplementor being deprecated.
|
| public FlushModeType | Returns: TheFlushModeType in effect for this Session.
Deprecated
since 6. there's no good reason to expose this here
Get the current FlushModeType for this session.
|
| public FlushMode | Returns: The flush modeRedeclares org. FlushMode for this session.
|
| public Interceptor | |
| public JdbcCoordinator | |
| public JdbcServices | |
| public LoadQueryInfluencers | Returns: theLoadQueryInfluencers associated with this session;
should never be null.Get the |
| public boolean | |
| public PersistenceContext | |
| public PersistenceContext | Returns: thePersistenceContext associated to this session.Similar to
|
| public default SharedSessionContractImplementor | getSession()
Implements org. WrapperOptions.
|
| public default SessionFactoryImplementor | getSessionFactory()
Implements org.
Deprecated
as a consequence of
Obtain the factory which created this session.
SessionFactoryImplementor being deprecated.
|
| public UUID | |
| public default Object | |
| public default TypeConfiguration | getTypeConfiguration()
Implements org. TypeConfiguration for the factory which created this session.
|
| public String | guessEntityName(Object entity)
Obtain an estimate of the entity name of the given entity instance,
which is not involved in an association, using only the
|
| public Object | |
| public void | initializeCollection(PersistentCollection<?> collection, boolean writing)
Initialize the given collection (if not already initialized). |
| public Object | instantiate(String entityName, Object id)
Instantiate the entity class, initializing with the given identifier. |
| public Object | instantiate(EntityPersister persister, Object id)
Instantiate the entity class of the given |
| public Object | internalLoad(String entityName, Object id, boolean eager, boolean nullable)
Obtain an entity instance with the given id, without checking if it was deleted or scheduled for deletion. |
| public boolean | isAutoCloseSessionEnabled()
Deprecated
since 6. there's no reason to expose this here
Is auto-close at transaction completion enabled?
|
| public boolean | Returns: true if the session is closed; false otherwise.Determines whether the session is closed. |
| public boolean | |
| public boolean | |
| public default boolean | isEnforcingFetchGraph()
Deprecated
for removal since 6. this is not used anywhere
Are we currently enforcing a fetch graph?
|
| public default boolean | |
| public default boolean | Returns: true if the session is closed, or if it's waiting
for auto-close; false otherwise.Determines whether the session is open or is waiting for auto-close. |
| public default boolean | |
| public default boolean | |
| public boolean | isTransactionInProgress()
Does this session have an active Hibernate transaction, or is it associated with a JTA transaction currently in progress? |
| public void | |
| public void | prepareForQueryExecution(boolean requiresTxn)
Prepare for the execution of a |
| public void | setAutoClear(boolean enabled)
Deprecated
since 6. there's no good reason to expose this here
Enable or disable automatic cache clearing from after transaction
completion.
|
| public void | |
| public void | |
| public default void | setEnforcingFetchGraph(boolean enforcingFetchGraph)
Deprecated
for removal since 6. this is not used anywhere
Enable or disable fetch graph enforcement.
|
| public void | setHibernateFlushMode(FlushMode
the new flush mode flushMode)Set the current |
| public void | |
| public boolean | shouldAutoClose()
Deprecated
since 6. there's no reason to expose this here
Should this session be automatically closed after the current
transaction completes?
|
| accessTransaction | back to summary |
|---|---|
| public Transaction accessTransaction() Retrieves the current This method is primarily for internal or integrator use.
| |
| afterOperation | back to summary |
|---|---|
| public void afterOperation(boolean success) Check if there is a Hibernate or JTA transaction in progress and, if there is not, flush if necessary, making sure that the connection has been committed (if it is not in autocommit mode), and finally run the after completion processing.
| |
| afterScrollOperation | back to summary |
|---|---|
| public void afterScrollOperation() Called after each operation on a | |
| asEventSource | back to summary |
|---|---|
| public default EventSource asEventSource() Cast this session to Only stateful session are sources of events. If this object is a stateless session, this method throws.
| |
| asSessionImplementor | back to summary |
|---|---|
| public default SessionImplementor asSessionImplementor() Cast this object to
| |
| asStatelessSession | back to summary |
|---|---|
| public default StatelessSession asStatelessSession() Cast this object to
| |
| autoFlushIfRequired | back to summary |
|---|---|
| public boolean autoFlushIfRequired(Set<String> querySpaces) throws HibernateException detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush | |
| bestGuessEntityName | back to summary |
|---|---|
| public String bestGuessEntityName(Object object) Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session. | |
| bestGuessEntityName | back to summary |
|---|---|
| public default String bestGuessEntityName(Object object, EntityEntry entry) Obtain the best estimate of the entity name of the given entity instance, which is not involved in an association, by also considering information held in the proxy, and whether the object is already associated with this session. | |
| checkOpen | back to summary |
|---|---|
| public default void checkOpen() Check whether the session is open, and if not:
| |
| checkOpen | back to summary |
|---|---|
| public void checkOpen(boolean markForRollbackIfClosed) Check whether the session is open, and if not:
| |
| checkTransactionNeededForUpdateOperation | back to summary |
|---|---|
| public default void checkTransactionNeededForUpdateOperation(String exceptionMessage) Check if an active
If an active transaction is necessary, but no transaction is active,
a
| |
| flush | back to summary |
|---|---|
| public void flush() Flush this session. | |
| generateEntityKey | back to summary |
|---|---|
| public EntityKey generateEntityKey(Object id, EntityPersister persister) Instantiate an
| |
| getCacheMode | back to summary |
|---|---|
| public CacheMode getCacheMode() Redeclares org. Get the current | |
| getCacheTransactionSynchronization | back to summary |
|---|---|
| public CacheTransactionSynchronization getCacheTransactionSynchronization() The current | |
| getConfiguredJdbcBatchSize | back to summary |
|---|---|
| public default Integer getConfiguredJdbcBatchSize() Get the currently configured JDBC batch size, which might have been specified at either the session or factory level.
| |
| getContextEntityIdentifier | back to summary |
|---|---|
| public Object getContextEntityIdentifier(Object object) Return the identifier of the persistent object, or null if it is not associated with this session. | |
| getEntityPersister | back to summary |
|---|---|
| public EntityPersister getEntityPersister(@Nullable String entityName, Object object) throws HibernateException Get the | |
| getEntityUsingInterceptor | back to summary |
|---|---|
| public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException Get the entity instance associated with the given | |
| getEventListenerManager | back to summary |
|---|---|
| public SessionEventListenerManager getEventListenerManager() Get the | |
| getExceptionConverter | back to summary |
|---|---|
| public ExceptionConverter getExceptionConverter() Obtain an The converter associated to a session might be lazily initialized, so only invoke this getter when there's an actual need to use it.
| |
| getFactory | back to summary |
|---|---|
| public SessionFactoryImplementor getFactory() Redeclares org. Deprecated as a consequence of Obtain the factory which created this session. | |
| getFlushMode | back to summary |
|---|---|
| public FlushModeType getFlushMode()
Deprecated since 6. there's no good reason to expose this here Get the current
For users of the Hibernate native APIs, we've had to rename this method
as defined by Hibernate historically because the JPA contract defines a method of the same
name, but returning the JPA
| |
| getHibernateFlushMode | back to summary |
|---|---|
| public FlushMode getHibernateFlushMode() Redeclares org. Get the current
| |
| getInterceptor | back to summary |
|---|---|
| public Interceptor getInterceptor() Retrieves the | |
| getJdbcCoordinator | back to summary |
|---|---|
| public JdbcCoordinator getJdbcCoordinator() Obtain the | |
| getJdbcServices | back to summary |
|---|---|
| public JdbcServices getJdbcServices() Obtain the | |
| getLoadQueryInfluencers | back to summary |
|---|---|
| public LoadQueryInfluencers getLoadQueryInfluencers() Get the
| |
| getNativeJdbcParametersIgnored | back to summary |
|---|---|
| public boolean getNativeJdbcParametersIgnored() | |
| getPersistenceContext | back to summary |
|---|---|
| public PersistenceContext getPersistenceContext() Get the persistence context for this session.
See Implementation Note This method is not extremely fast: if you need to
call the | |
| getPersistenceContextInternal | back to summary |
|---|---|
| public PersistenceContext getPersistenceContextInternal() Similar to
| |
| getSession | back to summary |
|---|---|
| public default SharedSessionContractImplementor getSession() Implements org. Returns this object, fulfilling the contract of
| |
| getSessionFactory | back to summary |
|---|---|
| public default SessionFactoryImplementor getSessionFactory() Implements org. Deprecated as a consequence of Obtain the factory which created this session.
| |
| getSessionIdentifier | back to summary |
|---|---|
| public UUID getSessionIdentifier() Obtain a The UUID is useful mainly for logging. | |
| getSessionToken | back to summary |
|---|---|
| public default Object getSessionToken() Obtain a "token" which uniquely identifies this session. | |
| getTypeConfiguration | back to summary |
|---|---|
| public default TypeConfiguration getTypeConfiguration() Implements org. Obtain the
| |
| guessEntityName | back to summary |
|---|---|
| public String guessEntityName(Object entity) throws HibernateException Obtain an estimate of the entity name of the given entity instance,
which is not involved in an association, using only the
| |
| immediateLoad | back to summary |
|---|---|
| public Object immediateLoad(String entityName, Object id) throws HibernateException Load an instance immediately. This method is only called when lazily initializing a proxy. Do not return the proxy. | |
| initializeCollection | back to summary |
|---|---|
| public void initializeCollection(PersistentCollection<?> collection, boolean writing) throws HibernateException Initialize the given collection (if not already initialized). | |
| instantiate | back to summary |
|---|---|
| public Object instantiate(String entityName, Object id) throws HibernateException Instantiate the entity class, initializing with the given identifier. | |
| instantiate | back to summary |
|---|---|
| public Object instantiate(EntityPersister persister, Object id) throws HibernateException Instantiate the entity class of the given
This is more efficient than | |
| internalLoad | back to summary |
|---|---|
| public Object internalLoad(String entityName, Object id, boolean eager, boolean nullable) throws HibernateException Obtain an entity instance with the given id, without checking if it was deleted or scheduled for deletion.
When | |
| isAutoCloseSessionEnabled | back to summary |
|---|---|
| public boolean isAutoCloseSessionEnabled()
Deprecated since 6. there's no reason to expose this here Is auto-close at transaction completion enabled?
| |
| isClosed | back to summary |
|---|---|
| public boolean isClosed() Determines whether the session is closed.
API Note Provided separately from
| |
| isCriteriaCopyTreeEnabled | back to summary |
|---|---|
| public boolean isCriteriaCopyTreeEnabled() | |
| isDefaultReadOnly | back to summary |
|---|---|
| public boolean isDefaultReadOnly() Are entities and proxies loaded by this session read-only by default? | |
| isEnforcingFetchGraph | back to summary |
|---|---|
| public default boolean isEnforcingFetchGraph()
Deprecated for removal since 6. this is not used anywhere Are we currently enforcing a fetch graph?
| |
| isEventSource | back to summary |
|---|---|
| public default boolean isEventSource() Determines if this session implements
Only stateful session are sources of events. If this object is
a stateless session, this method return | |
| isOpenOrWaitingForAutoClose | back to summary |
|---|---|
| public default boolean isOpenOrWaitingForAutoClose() Determines whether the session is open or is waiting for auto-close.
| |
| isSessionImplementor | back to summary |
|---|---|
| public default boolean isSessionImplementor() Does this object implement | |
| isStatelessSession | back to summary |
|---|---|
| public default boolean isStatelessSession() Does this object implement | |
| isTransactionInProgress | back to summary |
|---|---|
| public boolean isTransactionInProgress() Does this session have an active Hibernate transaction, or is it associated with a JTA transaction currently in progress? | |
| markForRollbackOnly | back to summary |
|---|---|
| public void markForRollbackOnly() Marks current transaction, if any, for rollback only. | |
| prepareForQueryExecution | back to summary |
|---|---|
| public void prepareForQueryExecution(boolean requiresTxn) Prepare for the execution of a | |
| setAutoClear | back to summary |
|---|---|
| public void setAutoClear(boolean enabled)
Deprecated since 6. there's no good reason to expose this here Enable or disable automatic cache clearing from after transaction completion.
| |
| setCacheMode | back to summary |
|---|---|
| public void setCacheMode(CacheMode cm) Set the current | |
| setCriteriaCopyTreeEnabled | back to summary |
|---|---|
| public void setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled) | |
| setEnforcingFetchGraph | back to summary |
|---|---|
| public default void setEnforcingFetchGraph(boolean enforcingFetchGraph)
Deprecated for removal since 6. this is not used anywhere Enable or disable fetch graph enforcement.
| |
| setHibernateFlushMode | back to summary |
|---|---|
| public void setHibernateFlushMode(FlushMode flushMode) Set the current The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
For a logically "read-only" session, it's reasonable to set the session
flush mode to
| |
| setNativeJdbcParametersIgnored | back to summary |
|---|---|
| public void setNativeJdbcParametersIgnored(boolean nativeJdbcParametersIgnored) | |
| shouldAutoClose | back to summary |
|---|---|
| public boolean shouldAutoClose()
Deprecated since 6. there's no reason to expose this here Should this session be automatically closed after the current transaction completes?
| |