org.hibernate.Session and
org.hibernate.StatelessSession as used by other parts of Hibernate (such as
org.hibernate.type.Type , EntityPersister and
org.hibernate.persister.collection.CollectionPersister implementors
A Session, through this interface and SharedSessionContractImplementor, implements:org.hibernate.resource.jdbc.spi.JdbcSessionOwner to drive the behavior of a "JDBC session".
Can therefor be used to construct a JdbcCoordinator, which (for now) models a "JDBC session"
Options
to drive the creation of the TransactionCoordinator delegate.
This allows it to be passed along to
org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder#buildTransactionCoordinator
org.hibernate.engine.jdbc.LobCreationContext to act as the context for JDBC LOB instance creation
org.hibernate.type.descriptor.WrapperOptions to fulfill the behavior needed while
binding/extracting values to/from JDBC as part of the Type contracts
| Modifier and Type | Method and Description |
|---|---|
| public Transaction | Returns: the transactionProvides access to the underlying transaction or creates a new transaction if one does not already exist or is active. |
| public void | |
| public String | |
| public default void | checkOpen()
Performs a check whether the Session is open, and if not:
|
| public void | checkOpen(boolean markForRollbackIfClosed)
Performs a check whether the Session is open, and if not:
|
| public default void | checkTransactionNeededForUpdateOperation(String
the message to use for the TransactionRequiredException exceptionMessage)Check if an active Transaction is necessary for the update operation to be executed. |
| public Connection | |
| public <T> QueryImplementor | Returns: The typed query
Deprecated
(since 5.2) - see deprecation note on
org.hibernate.jpa.spi.HibernateEntityManagerImplementor#createQuery(java.lang.String, java.lang.Class, javax.persistence.criteria.Selection, org.hibernate.jpa.spi.HibernateEntityManagerImplementor.QueryOptions)
|
| public int | executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)
Execute a native SQL update or delete query |
| public int | |
| public void | |
| public EntityKey | Returns: The entity keyThe entity id id, EntityPersister The entity persister persister)Hide the changing requirements of entity key creation |
| public CacheMode | |
| public CacheTransactionSynchronization | getCacheTransactionSynchronization()
The current CacheTransactionContext associated with the Session. |
| public default Integer | Returns: Session-level or or SessionFactory-level JDBC batch size.Get the currently configured JDBC batch size either at the Session-level or SessionFactory-level. |
| public Serializable | getContextEntityIdentifier(Object object)
Return the identifier of the persistent object, or null if not associated with the session |
| public int | |
| public EntityPersister | getEntityPersister(String
optional entity name entityName, Object the entity instance object)Get the EntityPersister for any instance |
| public Object | getEntityUsingInterceptor(EntityKey key)
Get the entity instance associated with the given Key, calling the Interceptor if necessary |
| public SessionEventListenerManager | |
| public ExceptionConverter | Returns: the ExceptionConverter for this Session.The converter associated to a Session might be lazily initialized: only invoke this getter when there is actual need to use it. |
| public SessionFactoryImplementor | getFactory()
Redeclares org.
Deprecated
as a consequence of
Get the creating SessionFactoryImplementor
SessionFactoryImplementor being deprecated.
|
| public FlushModeType | Returns: The FlushModeType in effect for this Session.Get the flush mode for this session. |
| public FlushMode | Returns: The flush modeRedeclares org. |
| public Interceptor | Returns: The interceptor.Retrieves the interceptor currently in use by this event source. |
| public JdbcCoordinator | |
| public JdbcServices | |
| public LoadQueryInfluencers | Returns: the load query influencers associated with this session; should never be null.Get the load query influencers associated with this session. |
| public PersistenceContext | |
| public PersistenceContext | Returns: the PersistenceContext associated to this session.This is similar to |
| public UUID | |
| public String | Returns: The tenant identifier; may benullRedeclares org. |
| public default long | |
| public long | getTransactionStartTimestamp()
Deprecated
no longer supported, when the Second Level Cache is enabled {
A "timestamp" at or before the start of the current transaction.
CacheTransactionSynchronization#getCachingTimestamp()} can be used.
|
| public String | |
| public Object | |
| public void | initializeCollection(PersistentCollection collection, boolean writing)
Initialize the collection (if not already initialized) |
| public Object | instantiate(String entityName, Serializable id)
Instantiate the entity class, initializing with the given identifier |
| public Object | instantiate(EntityPersister persister, Serializable id)
Instantiate the entity class of an EntityPersister, initializing with the given identifier. |
| public Object | internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)
Load an instance without checking if it was deleted. |
| public boolean | |
| public boolean | Returns: true if the session is closed; false otherwise.Checks whether the session is closed. |
| public default boolean | |
| public boolean | |
| public default boolean | Returns: true if the session is closed or if it's waiting for auto-close; false otherwise.Checks whether the session is open or is waiting for auto-close |
| public default boolean | |
| public boolean | isTransactionInProgress()
Does this Session have an active Hibernate transaction or is there a JTA transaction in progress? |
| public Iterator | |
| public Iterator | |
| public List | |
| public List | |
| public List | Returns: The result list.The specification of the native SQL query to execute. spec, QueryParameters The parameters by which to perform the execution. queryParameters)Execute a native SQL query, and return the results as a fully built list. |
| public List | |
| public List | |
| public void | |
| public ScrollableResultsImplementor | |
| public ScrollableResultsImplementor | |
| public ScrollableResultsImplementor | Returns: The resulting scrollable result.The specification of the native SQL query to execute. spec, QueryParameters The parameters by which to perform the execution. queryParameters)Execute a native SQL query, and return the results as a scrollable result. |
| public ScrollableResultsImplementor | |
| public void | setAutoClear(boolean enabled)
Enable/disable automatic cache clearing from after transaction completion (for EJB3) |
| public void | |
| public default void | |
| public void | setFlushMode(FlushMode
the new flush mode flushMode)
Deprecated
(since 5.2) use
Set the flush mode for this session.
setHibernateFlushMode(FlushMode) instead
|
| public void | |
| public boolean |
| accessTransaction | back to summary |
|---|---|
| public Transaction accessTransaction() Provides access to the underlying transaction or creates a new transaction if one does not already exist or is active. This is primarily for internal or integrator use.
| |
| afterScrollOperation | back to summary |
|---|---|
| public void afterScrollOperation() | |
| bestGuessEntityName | back to summary |
|---|---|
| public String bestGuessEntityName(Object object) The best guess entity name for an entity not in an association | |
| checkOpen | back to summary |
|---|---|
| public default void checkOpen() Performs a check whether the Session is open, and if not:
| |
| checkOpen | back to summary |
|---|---|
| public void checkOpen(boolean markForRollbackIfClosed) Performs a check whether the Session is open, and if not:
| |
| checkTransactionNeededForUpdateOperation | back to summary |
|---|---|
| public default void checkTransactionNeededForUpdateOperation(String exceptionMessage) Check if an active Transaction is necessary for the update operation to be executed. If an active Transaction is necessary but it is not then a TransactionRequiredException is raised.
| |
| connection | back to summary |
|---|---|
| public Connection connection() | |
| createQuery | back to summary |
|---|---|
| public <T> QueryImplementor Deprecated (since 5.2) - see deprecation note on org.hibernate.jpa.spi.HibernateEntityManagerImplementor#createQuery(java.lang.String, java.lang.Class, javax.persistence.criteria.Selection, org.hibernate.jpa.spi.HibernateEntityManagerImplementor.QueryOptions)
| |
| executeNativeUpdate | back to summary |
|---|---|
| public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException Execute a native SQL update or delete query | |
| executeUpdate | back to summary |
|---|---|
| public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException Execute a HQL update or delete query | |
| flush | back to summary |
|---|---|
| public void flush() | |
| generateEntityKey | back to summary |
|---|---|
| public EntityKey generateEntityKey(Serializable id, EntityPersister persister) Hide the changing requirements of entity key creation
| |
| getCacheMode | back to summary |
|---|---|
| public CacheMode getCacheMode() Redeclares org. | |
| getCacheTransactionSynchronization | back to summary |
|---|---|
| public CacheTransactionSynchronization getCacheTransactionSynchronization() The current CacheTransactionContext associated with the Session. This may
return | |
| getConfiguredJdbcBatchSize | back to summary |
|---|---|
| public default Integer getConfiguredJdbcBatchSize() Get the currently configured JDBC batch size either at the Session-level or SessionFactory-level. If the Session-level JDBC batch size was not configured, return the SessionFactory-level one.
| |
| getContextEntityIdentifier | back to summary |
|---|---|
| public Serializable getContextEntityIdentifier(Object object) Return the identifier of the persistent object, or null if not associated with the session | |
| getDontFlushFromFind | back to summary |
|---|---|
| public int getDontFlushFromFind() | |
| getEntityPersister | back to summary |
|---|---|
| public EntityPersister getEntityPersister(String entityName, Object object) throws HibernateException Get the EntityPersister for any instance | |
| getEntityUsingInterceptor | back to summary |
|---|---|
| public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException Get the entity instance associated with the given Key, calling the Interceptor if necessary | |
| getEventListenerManager | back to summary |
|---|---|
| public SessionEventListenerManager getEventListenerManager() | |
| getExceptionConverter | back to summary |
|---|---|
| public ExceptionConverter getExceptionConverter() The converter associated to a Session might be lazily initialized: only invoke this getter when there is actual need to use it.
| |
| getFactory | back to summary |
|---|---|
| public SessionFactoryImplementor getFactory() Redeclares org. Deprecated as a consequence of Get the creating SessionFactoryImplementor | |
| getFlushMode | back to summary |
|---|---|
| public FlushModeType getFlushMode() Get the flush mode for this session.
For users of the Hibernate native APIs, we've had to rename this method
as defined by Hibernate historically because the JPA contract defines a method of the same
name, but returning the JPA
| |
| getHibernateFlushMode | back to summary |
|---|---|
| public FlushMode getHibernateFlushMode() Redeclares org. Get the current flush mode for this session.
| |
| getInterceptor | back to summary |
|---|---|
| public Interceptor getInterceptor() Retrieves the interceptor currently in use by this event source.
| |
| getJdbcCoordinator | back to summary |
|---|---|
| public JdbcCoordinator getJdbcCoordinator() | |
| getJdbcServices | back to summary |
|---|---|
| public JdbcServices getJdbcServices() | |
| getLoadQueryInfluencers | back to summary |
|---|---|
| public LoadQueryInfluencers getLoadQueryInfluencers() Get the load query influencers associated with this session.
| |
| getPersistenceContext | back to summary |
|---|---|
| public PersistenceContext getPersistenceContext() Get the persistence context for this session.
See also | |
| getPersistenceContextInternal | back to summary |
|---|---|
| public PersistenceContext getPersistenceContextInternal() This is similar to
| |
| getSessionIdentifier | back to summary |
|---|---|
| public UUID getSessionIdentifier() A UUID associated with each Session. Useful mainly for logging.
| |
| getTenantIdentifier | back to summary |
|---|---|
| public String getTenantIdentifier() Redeclares org. The multi-tenancy tenant identifier, if one.
| |
| getTimestamp | back to summary |
|---|---|
| public default long getTimestamp()
Deprecated (since 5.3) Use
| |
| getTransactionStartTimestamp | back to summary |
|---|---|
| public long getTransactionStartTimestamp()
Deprecated no longer supported, when the Second Level Cache is enabled { A "timestamp" at or before the start of the current transaction. API Note This "timestamp" need not be related to timestamp in the Java Date/millisecond
sense. It just needs to be an incrementing value. See
| |
| guessEntityName | back to summary |
|---|---|
| public String guessEntityName(Object entity) throws HibernateException The guessed entity name for an entity not in an association | |
| immediateLoad | back to summary |
|---|---|
| public Object immediateLoad(String entityName, Serializable 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 collection (if not already initialized) | |
| instantiate | back to summary |
|---|---|
| public Object instantiate(String entityName, Serializable id) throws HibernateException Instantiate the entity class, initializing with the given identifier | |
| instantiate | back to summary |
|---|---|
| public Object instantiate(EntityPersister persister, Serializable id) throws HibernateException Instantiate the entity class of an EntityPersister, initializing with the given identifier.
This is more efficient than | |
| internalLoad | back to summary |
|---|---|
| public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException Load an instance without checking if it was deleted. When nullable is disabled this method may create a new proxy or return an existing proxy; if it does not exist, throw an exception. When nullable is enabled, the method does not create new proxies (but might return an existing proxy); if it does not exist, return null. When eager is enabled, the object is eagerly fetched | |
| isAutoCloseSessionEnabled | back to summary |
|---|---|
| public boolean isAutoCloseSessionEnabled() | |
| isClosed | back to summary |
|---|---|
| public boolean isClosed() Checks whether the session is closed. Provided separately from
| |
| isEnforcingFetchGraph | back to summary |
|---|---|
| public default boolean isEnforcingFetchGraph() | |
| isEventSource | back to summary |
|---|---|
| public boolean isEventSource() | |
| isOpenOrWaitingForAutoClose | back to summary |
|---|---|
| public default boolean isOpenOrWaitingForAutoClose() Checks whether the session is open or is waiting for auto-close
| |
| isQueryParametersValidationEnabled | back to summary |
|---|---|
| public default boolean isQueryParametersValidationEnabled() | |
| isTransactionInProgress | back to summary |
|---|---|
| public boolean isTransactionInProgress() Does this Session have an active Hibernate transaction or is there a JTA transaction in progress? | |
| iterate | back to summary |
|---|---|
| public Iterator Execute an iterate() query | |
| iterateFilter | back to summary |
|---|---|
| public Iterator Iterate a filter | |
| list | back to summary |
|---|---|
| public List Execute a find() query | |
| list | back to summary |
|---|---|
| public List Execute a criteria query | |
| list | back to summary |
|---|---|
| public List Execute a native SQL query, and return the results as a fully built list.
| |
| listCustomQuery | back to summary |
|---|---|
| public List Execute an SQL Query | |
| listFilter | back to summary |
|---|---|
| public List Execute a filter | |
| markForRollbackOnly | back to summary |
|---|---|
| public void markForRollbackOnly() Marks current transaction (if one) for rollback only | |
| scroll | back to summary |
|---|---|
| public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException Execute a scroll() query | |
| scroll | back to summary |
|---|---|
| public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode) Execute a criteria query | |
| scroll | back to summary |
|---|---|
| public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) Execute a native SQL query, and return the results as a scrollable result.
| |
| scrollCustomQuery | back to summary |
|---|---|
| public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException Execute an SQL Query | |
| setAutoClear | back to summary |
|---|---|
| public void setAutoClear(boolean enabled) Enable/disable automatic cache clearing from after transaction completion (for EJB3) | |
| setCacheMode | back to summary |
|---|---|
| public void setCacheMode(CacheMode cm) | |
| setEnforcingFetchGraph | back to summary |
|---|---|
| public default void setEnforcingFetchGraph(boolean enforcingFetchGraph) | |
| setFlushMode | back to summary |
|---|---|
| public void setFlushMode(FlushMode flushMode)
Deprecated (since 5.2) use Set the flush mode for this session. The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
For a logically "read only" session, it is reasonable to set the session's
flush mode to
| |
| setHibernateFlushMode | back to summary |
|---|---|
| public void setHibernateFlushMode(FlushMode flushMode) Set the flush mode for this session. The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
For a logically "read only" session, it is reasonable to set the session's
flush mode to
| |
| shouldAutoClose | back to summary |
|---|---|
| public boolean shouldAutoClose() | |