Interface SharedSessionContract
- All Superinterfaces:
AutoCloseable
,QueryProducer
,Serializable
- All Known Subinterfaces:
EventSource
,Session
,SessionImplementor
,SharedSessionContractImplementor
,StatelessSession
- All Known Implementing Classes:
AbstractDelegateSessionImplementor
,AbstractSharedSessionContract
,SessionDelegatorBaseImpl
,SessionImpl
,SessionLazyDelegator
,SharedSessionDelegatorBaseImpl
,StatelessSessionImpl
,ToOneDelegateSessionImplementor
Session
and StatelessSession
.-
Method Summary
Modifier and TypeMethodDescriptionBegin a unit of work and return the associatedTransaction
object.void
close()
End the session by releasing the JDBC connection and cleaning up.<T> RootGraph<T>
createEntityGraph
(Class<T> rootType) Create a new mutable instance ofEntityGraph
, with only a root node, allowing programmatic definition of the graph from scratch.<T> RootGraph<T>
createEntityGraph
(Class<T> rootType, String graphName) Create a new mutable instance ofEntityGraph
, based on a predefined named entity graph, allowing customization of the graph, or returnnull
if there is no predefined graph with the given name.RootGraph<?>
createEntityGraph
(String graphName) Create a new mutable instance ofEntityGraph
, based on a predefined named entity graph, allowing customization of the graph, or returnnull
if there is no predefined graph with the given name.Obtain aProcedureCall
based on a named templatecreateStoredProcedureCall
(String procedureName) Create aProcedureCall
to a stored procedure.createStoredProcedureCall
(String procedureName, Class<?>... resultClasses) Create aProcedureCall
to a stored procedure with the given result set entity mappings.createStoredProcedureCall
(String procedureName, String... resultSetMappings) Create aProcedureCall
to a stored procedure with the given result set entity mappings.createStoredProcedureQuery
(String procedureName) Create aProcedureCall
to a stored procedure.createStoredProcedureQuery
(String procedureName, Class<?>... resultClasses) Create aProcedureCall
to a stored procedure with the given result set entity mappings.createStoredProcedureQuery
(String procedureName, String... resultSetMappings) Create aProcedureCall
to a stored procedure with the given result set entity mappings.void
disableFilter
(String filterName) Disable the named filter for the current session.<T> T
doReturningWork
(ReturningWork<T> work) Perform work using theConnection
underlying by this session, and return a result.void
Perform work using theConnection
underlying by this session.enableFilter
(String filterName) Enable the named filter for this current session.Get the current cache mode for this session.getEnabledFilter
(String filterName) Retrieve a currently enabled filter by name.RootGraph<?>
getEntityGraph
(String graphName) Obtain an immutable reference to a predefined named entity graph or returnnull
if there is no predefined graph with the given name.<T> List<EntityGraph<? super T>>
getEntityGraphs
(Class<T> entityClass) Retrieve all namedEntityGraph
s with the given root entity type.The factory which created this session.Get the session-level JDBC batch size for the current session.getNamedProcedureCall
(String name) Obtain aProcedureCall
based on a named templateObtain the tenant identifier associated with this session, as a string.Obtain the tenant identifier associated with this session.Get theTransaction
instance associated with this session.boolean
Check if the session is currently connected.boolean
Check if the session is joined to the current transaction.boolean
isOpen()
Check if the session is still open.void
Join the currently-active JTA transaction.void
setCacheMode
(CacheMode cacheMode) Set the current cache mode for this session.void
setJdbcBatchSize
(Integer jdbcBatchSize) Set the session-level JDBC batch size.Methods inherited from interface org.hibernate.query.QueryProducer
createMutationQuery, createMutationQuery, createMutationQuery, createMutationQuery, createMutationQuery, createNamedMutationQuery, createNamedQuery, createNamedQuery, createNamedSelectionQuery, createNamedSelectionQuery, createNativeMutationQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery, getNamedNativeQuery, getNamedNativeQuery, getNamedQuery
-
Method Details
-
getTenantIdentifier
String getTenantIdentifier()Obtain the tenant identifier associated with this session, as a string.- Returns:
- The tenant identifier associated with this session, or
null
- See Also:
-
getTenantIdentifierValue
Object getTenantIdentifierValue()Obtain the tenant identifier associated with this session.- Returns:
- The tenant identifier associated with this session, or
null
- Since:
- 6.4
- See Also:
-
getCacheMode
CacheMode getCacheMode()Get the current cache mode for this session.- Returns:
- the current cache mode
-
setCacheMode
Set the current cache mode for this session.The cache mode determines the manner in which this session can interact with the second level cache.
- Parameters:
cacheMode
- the new cache mode
-
close
End the session by releasing the JDBC connection and cleaning up.- Specified by:
close
in interfaceAutoCloseable
- Throws:
HibernateException
- Indicates problems cleaning up.
-
isOpen
boolean isOpen()Check if the session is still open.- Returns:
true
if it is open
-
isConnected
boolean isConnected()Check if the session is currently connected.- Returns:
true
if it is connected
-
beginTransaction
Transaction beginTransaction()Begin a unit of work and return the associatedTransaction
object. If a new underlying transaction is required, begin the transaction. Otherwise, continue the new work in the context of the existing underlying transaction.- Returns:
- an instance of
Transaction
representing the new transaction - See Also:
- API Note:
- The JPA-standard way to begin a new resource-local transaction is by calling
getTransaction().begin()
. But it's not always safe to execute this idiom.- JPA doesn't allow an
EntityTransaction
to represent a JTA transaction context. Therefore, when strict JPA transaction compliance is enabled via, for example, setting "hibernate.jpa.compliance.transaction", the call togetTransaction()
fails if transactions are managed by JTA.On the other hand, this method does not fail when JTA transaction management is used, not even if strict JPA transaction compliance is enabled.
- Even when resource-local transactions are in use, and even when strict JPA
transaction compliance is disabled, the call to
begin()
fails if a transaction is already active.This method never fails when a transaction is already active. Instead,
beginTransaction()
simply returns theTransaction
object representing the active transaction.
- JPA doesn't allow an
-
getTransaction
Transaction getTransaction()Get theTransaction
instance associated with this session.- Returns:
- an instance of
Transaction
representing the transaction associated with this session - See Also:
- API Note:
- This method is the JPA-standard way to obtain an instance of
EntityTransaction
representing a resource-local transaction. But JPA doesn't allow anEntityTransaction
to represent a JTA transaction. Therefore, when strict JPA transaction compliance is enabled via, for example, setting "hibernate.jpa.compliance.transaction", this method fails if transactions are managed by JTA.On the other hand, when JTA transaction management is used, and when strict JPA transaction compliance is disabled, this method happily returns a
Transaction
representing the current JTA transaction context.
-
joinTransaction
void joinTransaction()Join the currently-active JTA transaction.- Since:
- 6.2
- See Also:
-
isJoinedToTransaction
boolean isJoinedToTransaction()Check if the session is joined to the current transaction.- Since:
- 6.2
- See Also:
-
getNamedProcedureCall
Obtain aProcedureCall
based on a named template- Parameters:
name
- The name given to the template- Returns:
- The ProcedureCall
- See Also:
-
createStoredProcedureCall
Create aProcedureCall
to a stored procedure.- Parameters:
procedureName
- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureCall
Create aProcedureCall
to a stored procedure with the given result set entity mappings. Each given class is considered a "root return".- Parameters:
procedureName
- The name of the procedure.resultClasses
- The entity(s) to map the result on to.- Returns:
- The representation of the procedure call.
-
createStoredProcedureCall
Create aProcedureCall
to a stored procedure with the given result set entity mappings.- 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.
-
createNamedStoredProcedureQuery
Obtain aProcedureCall
based on a named template- Parameters:
name
- The name given to the template- Returns:
- The ProcedureCall
- See Also:
-
createStoredProcedureQuery
Create aProcedureCall
to a stored procedure.- Parameters:
procedureName
- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureQuery
Create aProcedureCall
to a stored procedure with the given result set entity mappings. Each given class is considered a "root return".- 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
Create aProcedureCall
to a stored procedure with the given result set entity mappings.- 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.
-
getJdbcBatchSize
Integer getJdbcBatchSize()Get the session-level JDBC batch size for the current session.- Returns:
- the current session-level JDBC batch size
- Since:
- 5.2
- See Also:
-
setJdbcBatchSize
Set the session-level JDBC batch size. Override the factory-level JDBC batch size controlled by the configuration property "hibernate.jdbc.batch_size".- Parameters:
jdbcBatchSize
- the new session-level JDBC batch size- Since:
- 5.2
- See Also:
-
getCriteriaBuilder
HibernateCriteriaBuilder getCriteriaBuilder()- Returns:
- an instance of
HibernateCriteriaBuilder
- Throws:
IllegalStateException
- if the session has been closed- See Also:
-
doWork
Perform work using theConnection
underlying by this session.- Parameters:
work
- The work to be performed.- Throws:
HibernateException
- Generally indicates wrappedSQLException
- API Note:
- This method competes with the JPA-defined method
EntityManager.runWithConnection(jakarta.persistence.ConnectionConsumer<C>)
-
doReturningWork
Perform work using theConnection
underlying by this session, and return a result.- Type Parameters:
T
- The type of the result returned from the work- Parameters:
work
- The work to be performed.- Returns:
- the result of calling
ReturningWork.execute(java.sql.Connection)
. - Throws:
HibernateException
- Generally indicates wrappedSQLException
- API Note:
- This method competes with the JPA-defined method
EntityManager.callWithConnection(jakarta.persistence.ConnectionFunction<C, T>)
-
createEntityGraph
Create a new mutable instance ofEntityGraph
, with only a root node, allowing programmatic definition of the graph from scratch.- Parameters:
rootType
- the root entity class of the graph- Since:
- 6.3
- See Also:
-
createEntityGraph
Create a new mutable instance ofEntityGraph
, based on a predefined named entity graph, allowing customization of the graph, or returnnull
if there is no predefined graph with the given name.- Parameters:
graphName
- the name of the graph- Since:
- 6.3
- See Also:
- API Note:
- This method returns
RootGraph<?>
, requiring an unchecked typecast before use. It's cleaner to obtain a graph usingcreateEntityGraph(Class, String)
instead.
-
createEntityGraph
Create a new mutable instance ofEntityGraph
, based on a predefined named entity graph, allowing customization of the graph, or returnnull
if there is no predefined graph with the given name.- Parameters:
rootType
- the root entity class of the graphgraphName
- the name of the predefined named entity graph- Throws:
IllegalArgumentException
- if the graph with the given name does not have the given entity type as its root- Since:
- 6.3
- See Also:
-
getEntityGraph
Obtain an immutable reference to a predefined named entity graph or returnnull
if there is no predefined graph with the given name.- Parameters:
graphName
- the name of the predefined named entity graph- Since:
- 6.3
- See Also:
- API Note:
- This method returns
RootGraph<?>
, requiring an unchecked typecast before use. It's cleaner to obtain a graph using the static metamodel for the class which defines the graph, or by callingEntityManagerFactory.getNamedEntityGraphs(Class)
instead.
-
getEntityGraphs
Retrieve all namedEntityGraph
s with the given root entity type. -
enableFilter
Enable the named filter for this current session.The returned
Filter
object must be used to bind arguments to parameters of the filter, and every parameter must be set before any other operation of this session is called.- Parameters:
filterName
- the name of the filter to be enabled.- Returns:
- the
Filter
instance representing the enabled filter. - Throws:
UnknownFilterException
- if there is no such filter- See Also:
-
getEnabledFilter
Retrieve a currently enabled filter by name.- Parameters:
filterName
- the name of the filter to be retrieved.- Returns:
- the
Filter
instance representing the enabled filter.
-
disableFilter
Disable the named filter for the current session.- Parameters:
filterName
- the name of the filter to be disabled.
-
getFactory
SessionFactory getFactory()The factory which created this session.
-