Interface SharedSessionContract
- All Superinterfaces:
AutoCloseable, EntityHandler, Serializable
- All Known Subinterfaces:
EventSource, Session, SessionImplementor, SharedSessionContractImplementor, StatelessSession, StatelessSessionImplementor
- All Known Implementing Classes:
SessionDelegatorBaseImpl, SessionLazyDelegator
Session and StatelessSession.-
Method Summary
Modifier and TypeMethodDescriptionBegin a unit of work and return the associatedTransactionobject.voidclose()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) Deprecated, for removal: This API element is subject to removal in a future version.RootGraph<?> createEntityGraph(String graphName) Deprecated, for removal: This API element is subject to removal in a future version.UsegetEntityGraph(String)instead.createMutationQuery(CriteriaStatement<?> criteriaStatement) Create aMutationQueryfrom the given update criteria treecreateMutationQuery(String hqlString) Create aMutationQueryreference for the given HQL insert, update, or delete statement.createMutationQuery(JpaCriteriaInsert<?> insert) Create aMutationQueryfrom the given insert criteria treeCreate aMutationQueryinstance for the given named insert, update, or delete HQL query.createNamedQuery(String name) Create an instance ofQueryfor the given named query or statement, without indicating the expected result type, if any, nor whether the query is a typed query which returns a result list, or an update, delete, or insert statement.<R> SelectionQuery<R> createNamedQuery(String name, Class<R> resultClass) Create a typedQueryinstance for the given named query.<R> NativeQuery<R> createNamedQuery(String name, String resultSetMappingName) <R> NativeQuery<R> createNamedQuery(String name, String resultSetMappingName, Class<R> resultClass) <R> SelectionQuery<R> createNamedSelectionQuery(String name, Class<R> resultType) Create aSelectionQueryinstance for the namedNamedQuerywith the given result type.createNamedStatement(String name) Obtain aProcedureCallbased on a named templatecreateNativeMutationQuery(String sqlString) Create aNativeQueryinstance for the given native SQL statement.default <R> NativeQuery<R> createNativeQuery(Class<R> resultClass, String queryString) Synonym for createNativeQuery(String,Class), offering generally easier readability for use code.NativeQuery<?> createNativeQuery(String sqlString) Create aNativeQueryinstance for the given native SQL query.<T> TypedQuery<T> createNativeQuery(String sql, jakarta.persistence.sql.ResultSetMapping<T> resultSetMapping) <R> NativeQuery<R> createNativeQuery(String sqlString, Class<R> resultClass) Create aNativeQueryinstance for the given native SQL query using an implicit mapping to the specified Java type.<R> NativeQuery<R> createNativeQuery(String sqlString, Class<R> resultClass, String tableAlias) Create aNativeQueryinstance for the given native SQL query using an implicit mapping to the specified Java entity type.NativeQuery<?> createNativeQuery(String sql, String resultSetMapping) <R> NativeQuery<R> createNativeQuery(String sqlString, String resultSetMappingName, Class<R> resultClass) Create aNativeQueryinstance for the given native SQL query using an explicit mapping to the specified Java type.<T> SelectionQuery<T> createQuery(CriteriaSelect<T> criteriaSelect) <R> SelectionQuery<R> createQuery(TypedQueryReference<R> typedQueryReference) Create a typedQueryinstance for the given typed query reference.default <R> SelectionQuery<R> createQuery(Class<R> resultClass, String hqlString) Synonym for createQuery(String,Class), offering generally easier readability for use code.createQuery(String queryString) Create an instance ofQueryfor the given HQL query or statement, without indicating the expected result type, if any, nor whether the query is a typed query which returns a result list, or an update, delete, or insert statement.<T> SelectionQuery<T> createQuery(String hqlString, EntityGraph<T> entityGraph) <R> SelectionQuery<R> createQuery(String queryString, Class<R> resultClass) Create a typedQueryinstance for the given HQL query string and given query result type.<R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria) Create aSelectionQueryreference for the givenCriteriaQuery.<R> SelectionQuery<R> createSelectionQuery(CriteriaSelect<R> criteria) Create aSelectionQueryreference for the givenCriteriaQuery.<R> SelectionQuery<R> createSelectionQuery(String hqlString, EntityGraph<R> resultGraph) Create aSelectionQueryinstance for the given HQL query string and givenEntityGraph, which is interpreted as a load graph.<R> SelectionQuery<R> createSelectionQuery(String hqlString, Class<R> resultType) Create aSelectionQueryinstance for the given HQL query string and given query result type.createStatement(CriteriaStatement<?> criteriaStatement) createStatement(StatementReference statementReference) createStatement(String hqlString) 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.voiddisableFilter(String filterName) Disable the named filter for the current session.<T> TdoReturningWork(ReturningWork<T> work) Perform work using theConnectionunderlying by this session, and return a result.voidPerform work using theConnectionunderlying by this session.enableFilter(String filterName) Enable the named filter for this current session.default ObjectCorollary toEntityHandler.find(Class,Object)for dynamic models.find(String entityName, Object key, FindOption... findOptions) Corollary toEntityHandler.find(Class,Object,FindOption...)for dynamic models.default <R> RfromTransaction(Function<? super Transaction, R> action) Obtain a value within the bounds of a transaction associated with this session.default ObjectForm offind(String,Object)throwingEntityNotFoundExceptionif no entity exists for that id rather than returning null.get(String entityName, Object key, FindOption... findOptions) Form offind(String,Object,FindOption...)throwingEntityNotFoundExceptionif no entity exists for that id rather than returning null.Get the current cache mode for this session.getEnabledFilter(String filterName) Retrieve a currently enabled filter by name.<T> RootGraph<T> getEntityGraph(Class<T> rootType, String graphName) Obtain a mutable copy of a predefined named entity graph whose root type is exactly the given entity type.RootGraph<?> getEntityGraph(String graphName) Obtain a mutable copy of a predefined named entity graph.<T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass) Retrieve all namedEntityGraphs 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 aProcedureCallbased on a named templateObtain the tenant identifier associated with this session, as a string.Obtain the tenant identifier associated with this session.Get theTransactioninstance associated with this session.default voidinTransaction(Consumer<? super Transaction> action) Perform an action within the bounds of a transaction associated with this session.booleanCheck if the session is currently connected.booleanCheck if the session is joined to the current transaction.booleanisOpen()Check if the session is still open.voidJoin the currently active JTA transaction.Obtain aSessionbuilder with the ability to copy certain information from this session.voidsetCacheMode(CacheMode cacheMode) Set the current cache mode for this session.voidsetJdbcBatchSize(Integer jdbcBatchSize) Set the session-level JDBC batch size.Obtain aStatelessSessionbuilder with the ability to copy certain information from this session.Methods inherited from interface EntityHandler
callWithConnection, find, find, find, findMultiple, findMultiple, get, get, get, getCacheRetrieveMode, getCacheStoreMode, getEntityManagerFactory, getMetamodel, getMultiple, getMultiple, getProperties, runWithConnection, setCacheRetrieveMode, setCacheStoreMode, setProperty, unwrap
-
Method Details
-
getTenantIdentifier
-
getTenantIdentifierValue
-
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceEntityHandler- Throws:
HibernateException- Indicates problems cleaning up.
-
isOpen
boolean isOpen()Check if the session is still open.- Specified by:
isOpenin interfaceEntityHandler- Returns:
trueif it is open
-
isConnected
boolean isConnected()Check if the session is currently connected.- Returns:
trueif it is connected
-
beginTransaction
Begin a unit of work and return the associatedTransactionobject. 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
Transactionrepresenting 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
EntityTransactionto 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 theTransactionobject representing the active transaction.
- JPA doesn't allow an
-
getTransaction
Get theTransactioninstance associated with this session.- Specified by:
getTransactionin interfaceEntityHandler- Returns:
- an instance of
Transactionrepresenting the transaction associated with this session - See Also:
- API Note:
- This method is the JPA-standard way to obtain an instance of
EntityTransactionrepresenting a resource-local transaction. But JPA doesn't allow anEntityTransactionto 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
Transactionrepresenting 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:
-
find
Corollary toEntityHandler.find(Class,Object)for dynamic models.- Parameters:
entityName- The entity nameid- The identifier- Returns:
- The persistent instance, or null
- Throws:
IllegalArgumentException- If the given name does not match a mapped dynamic entity- See Also:
-
find
@Nullable Object find(@Nonnull String entityName, @Nonnull Object key, @Nullable FindOption... findOptions) Corollary toEntityHandler.find(Class,Object,FindOption...)for dynamic models.- Parameters:
entityName- The entity namekey- The key (primary or natural, based onKeyType)findOptions- Options for the load operation.- Returns:
- The persistent instance, or null
- Throws:
IllegalArgumentException- If the given name does not match a mapped dynamic entity- See Also:
-
get
Form offind(String,Object)throwingEntityNotFoundExceptionif no entity exists for that id rather than returning null.- Parameters:
entityName- The entity nameid- The identifier- Returns:
- The persistent instance
- Throws:
IllegalArgumentException- If the given name does not match a mapped dynamic entityEntityNotFoundException- if no entity was found for the givenid- See Also:
-
get
@Nonnull Object get(@Nonnull String entityName, @Nonnull Object key, @Nullable FindOption... findOptions) Form offind(String,Object,FindOption...)throwingEntityNotFoundExceptionif no entity exists for that id rather than returning null.- Parameters:
entityName- The entity namekey- The key (primary or natural, based onKeyType)findOptions- Options for the load operation.- Returns:
- a persistent instance
- Throws:
IllegalArgumentException- If the given name does not match a mapped dynamic entityEntityNotFoundException- if no entity was found for the givenkey- See Also:
-
createQuery
@Nonnull <R> SelectionQuery<R> createQuery(@Nonnull String queryString, @Nonnull Class<R> resultClass) Create a typedQueryinstance for the given HQL query string and given query result type.- If the query has a single item in the
selectlist, then the select item must be assignable to the given result type. - Otherwise, if there are multiple select items, then the
select items will be packaged into an instance of the
result type. The result type must have an appropriate
constructor with parameter types matching the select items,
or it must be one of the types
Object[],List,Map, orTuple.
If a query has no explicit
selectlist, the select list is inferred from the given query result type:- if the result type is an entity type, the query must have
exactly one root entity in the
fromclause, it must be assignable to the result type, and the inferred select list will contain just that entity, or - otherwise, the select list contains every root entity and
every non-
fetchjoined entity, and each query result will be packaged into an instance of the result type, just as specified above.
If a query has no explicit
fromclause, and the given result type is an entity type, the root entity is inferred to be the result type.Passing
Object.classas the query result type is not recommended.The returned
Querymay be executed by callingSelectionQuery.getResultList()orSelectionQuery.getSingleResult().- Specified by:
createQueryin interfaceEntityHandler- Parameters:
queryString- The HQL queryresultClass- TheClassobject representing the query result type, which should not beObject.class- Returns:
- The
Queryinstance for manipulation and execution - See Also:
- If the query has a single item in the
-
createQuery
@Nonnull default <R> SelectionQuery<R> createQuery(@Nonnull Class<R> resultClass, @Nonnull String hqlString) Synonym for createQuery(String,Class), offering generally easier readability for use code. For example
var peeps = session.createQuery(Person.class, "some really long query string" ) ... .list();as opposed to
var peeps = session.createQuery("some really long query string", Person.class) ... .list(); -
createQuery
@Nonnull <T> SelectionQuery<T> createQuery(@Nonnull String hqlString, @Nonnull EntityGraph<T> entityGraph) - Specified by:
createQueryin interfaceEntityHandler- See Also:
-
createSelectionQuery
Create aSelectionQueryinstance for the given HQL query string and given query result type.- If the query has a single item in the
selectlist, then the select item must be assignable to the given result type. - Otherwise, if there are multiple select items, then the
select items will be packaged into an instance of the
result type. The result type must have an appropriate
constructor with parameter types matching the select items,
or it must be one of the types
Object[],List,Map, orTuple.
If a query has no explicit
selectlist, the select list is inferred from the given query result type:- if the result type is an entity type, the query must have
exactly one root entity in the
fromclause, it must be assignable to the result type, and the inferred select list will contain just that entity, or - otherwise, the select list contains every root entity and
every non-
fetchjoined entity, and each query result will be packaged into an instance of the result type, just as specified above.
If a query has no explicit
fromclause, and the given result type is an entity type, the root entity is inferred to be the result type.Passing
Object.classas the query result type is not recommended.The returned
Querymay be executed by callingSelectionQuery.getResultList()orSelectionQuery.getSingleResult().- Parameters:
hqlString- The HQLselectquery as a stringresultType- TheClassobject representing the query result type, which should not beObject.class- Throws:
IllegalSelectQueryException- if the given HQL query is aninsert,updateordeletestatement- See Also:
- If the query has a single item in the
-
createSelectionQuery
Create aSelectionQueryinstance for the given HQL query string and givenEntityGraph, which is interpreted as a load graph. The query result type is the root entity of the given graph.- If the query has an explicit
selectclause, there must be a single item in theselectlist, and the select item must be assignable to the root type of the given graph. - Otherwise, if a query has no explicit
selectlist, the select list is inferred from the given entity graph. The query must have exactly one root entity in thefromclause, it must be assignable to the root type of the given graph, and the inferred select list will contain just that entity.
If a query has no explicit
fromclause, and the given result type is an entity type, the root entity is inferred to be the result type.The returned
Querymay be executed by callingSelectionQuery.getResultList()orSelectionQuery.getSingleResult().- Parameters:
hqlString- The HQLselectquery as a stringresultGraph- AnEntityGraphwhose root type is the query result type, which is interpreted as a load graph- Throws:
IllegalSelectQueryException- if the given HQL query is aninsert,updateordeletestatement- Since:
- 7.0
- See Also:
- If the query has an explicit
-
createMutationQuery
Create aMutationQueryreference for the given HQL insert, update, or delete statement.- Parameters:
hqlString- The HQLinsert,update, ordeletestatement- Throws:
IllegalMutationQueryException- if the given HQL query is aselectquery
-
createStatement
- Specified by:
createStatementin interfaceEntityHandler
-
createStatement
- Specified by:
createStatementin interfaceEntityHandler
-
createQuery
Create a typedQueryinstance for the given typed query reference.- Specified by:
createQueryin interfaceEntityHandler- Parameters:
typedQueryReference- the type query reference- Returns:
- The
Queryinstance for execution - Throws:
IllegalArgumentException- if a query has not been defined with the name of the typed query reference or if the query result is found to not be assignable to result class of the typed query reference- See Also:
-
createQuery
- Specified by:
createQueryin interfaceEntityHandler- See Also:
-
createStatement
- Specified by:
createStatementin interfaceEntityHandler- See Also:
-
createSelectionQuery
Create aSelectionQueryreference for the givenCriteriaQuery.- See Also:
-
createSelectionQuery
Create aSelectionQueryreference for the givenCriteriaQuery.- See Also:
-
createMutationQuery
Create aMutationQueryfrom the given update criteria tree -
createMutationQuery
Create aMutationQueryfrom the given insert criteria tree -
createNativeQuery
Create aNativeQueryinstance for the given native SQL query.- Specified by:
createNativeQueryin interfaceEntityHandler- Parameters:
sqlString- The native (SQL) query string- Returns:
- The
NativeQueryinstance for manipulation and execution - See Also:
-
createNativeQuery
@Nonnull <R> NativeQuery<R> createNativeQuery(@Nonnull String sqlString, @Nonnull Class<R> resultClass) Create aNativeQueryinstance for the given native SQL query using an implicit mapping to the specified Java type.- If the given class is an entity class, this method is equivalent
to
createNativeQuery(sqlString).addEntity(resultClass). - If the given class has a registered
JavaType, then the query must return a result set with a single column whoseJdbcTypeis compatible with thatJavaType. - Otherwise, the select items will be packaged into an instance of
the result type. The result type must have an appropriate
constructor with parameter types matching the select items, or it
must be one of the types
Object[],List,Map, orTuple.
- Specified by:
createNativeQueryin interfaceEntityHandler- Parameters:
sqlString- The native (SQL) query stringresultClass- The Java type to map results to- Returns:
- The
NativeQueryinstance for manipulation and execution - See Also:
- If the given class is an entity class, this method is equivalent
to
-
createNativeQuery
Synonym for createNativeQuery(String,Class), offering generally easier readability for use code. For example
var peeps = session.createNativeQuery(Person.class, "some really long query string" ) ... .list();as opposed to
var peeps = session.createNativeQuery("some really long query string", Person.class) ... .list(); -
createNativeQuery
Create aNativeQueryinstance for the given native SQL query using an implicit mapping to the specified Java entity type.The given class must be an entity class. This method is equivalent to
createNativeQuery(sqlString).addEntity(tableAlias, resultClass).- Parameters:
sqlString- Native (SQL) query stringresultClass- The Java entity class to map results totableAlias- The table alias for columns in the result set- Returns:
- The
NativeQueryinstance for manipulation and execution - See Also:
-
createNativeQuery
<R> NativeQuery<R> createNativeQuery(String sqlString, String resultSetMappingName, Class<R> resultClass) Create aNativeQueryinstance for the given native SQL query using an explicit mapping to the specified Java type.The given result set mapping name must identify a mapping defined by a
SqlResultSetMappingannotation.- Parameters:
sqlString- The native (SQL) query stringresultSetMappingName- The explicit result mapping name- Returns:
- The
NativeQueryinstance for manipulation and execution - See Also:
-
createNativeMutationQuery
Create aNativeQueryinstance for the given native SQL statement.- Parameters:
sqlString- a native SQL statement string- Returns:
- The NativeQuery instance for manipulation and execution
-
createNamedQuery
@Nonnull <R> SelectionQuery<R> createNamedQuery(@Nonnull String name, @Nonnull Class<R> resultClass) Create a typedQueryinstance for the given named query. The named query might be defined in HQL or in native SQL.- Specified by:
createNamedQueryin interfaceEntityHandler- Parameters:
name- the name of a query defined in metadataresultClass- the type of the query result- Returns:
- The
Queryinstance for manipulation and execution - Throws:
IllegalArgumentException- if a query has not been defined with the given name or if the query string is found to be invalid or if the query result is found to not be assignable to the specified type- See Also:
-
createNamedStatement
- Specified by:
createNamedStatementin interfaceEntityHandler
-
createNamedQuery
-
createNamedQuery
-
createNativeStatement
- Specified by:
createNativeStatementin interfaceEntityHandler
-
createNativeQuery
- Specified by:
createNativeQueryin interfaceEntityHandler
-
createNativeQuery
@Nonnull <T> TypedQuery<T> createNativeQuery(@Nonnull String sql, @Nonnull jakarta.persistence.sql.ResultSetMapping<T> resultSetMapping) - Specified by:
createNativeQueryin interfaceEntityHandler
-
createNamedSelectionQuery
@Nonnull <R> SelectionQuery<R> createNamedSelectionQuery(@Nonnull String name, @Nonnull Class<R> resultType) Create aSelectionQueryinstance for the namedNamedQuerywith the given result type.- Throws:
IllegalSelectQueryException- if the given HQL query is not a select queryUnknownNamedQueryException- if no query has been defined with the given name
-
createNamedMutationQuery
Create aMutationQueryinstance for the given named insert, update, or delete HQL query. The named query might be defined as HQL) or native-SQL.- Throws:
IllegalMutationQueryException- if the given HQL query is a select queryUnknownNamedQueryException- if no query has been defined with the given name
-
getNamedProcedureCall
Obtain aProcedureCallbased on a named template- Parameters:
name- The name given to the template- Returns:
- The ProcedureCall
- See Also:
-
createStoredProcedureCall
Create aProcedureCallto a stored procedure.- Parameters:
procedureName- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureCall
@Nonnull ProcedureCall createStoredProcedureCall(@Nonnull String procedureName, @Nonnull Class<?>... resultClasses) Create aProcedureCallto 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
@Nonnull ProcedureCall createStoredProcedureCall(@Nonnull String procedureName, @Nonnull String... resultSetMappings) Create aProcedureCallto 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 aProcedureCallbased on a named template- Specified by:
createNamedStoredProcedureQueryin interfaceEntityHandler- Parameters:
name- The name given to the template- Returns:
- The ProcedureCall
- See Also:
-
createStoredProcedureQuery
Create aProcedureCallto a stored procedure.- Specified by:
createStoredProcedureQueryin interfaceEntityHandler- Parameters:
procedureName- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureQuery
@Nonnull ProcedureCall createStoredProcedureQuery(@Nonnull String procedureName, @Nonnull Class<?>... resultClasses) Create aProcedureCallto a stored procedure with the given result set entity mappings. Each given class is considered a "root return".- Specified by:
createStoredProcedureQueryin interfaceEntityHandler- 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
@Nonnull ProcedureCall createStoredProcedureQuery(@Nonnull String procedureName, @Nonnull String... resultSetMappings) Create aProcedureCallto a stored procedure with the given result set entity mappings.- Specified by:
createStoredProcedureQueryin interfaceEntityHandler- 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:
- API Note:
- Setting a session-level JDBC batch size for a
StatelessSessiontriggers a sort of write-behind behaviour where operations are batched and executed asynchronously, undermining the semantics of the stateless programming model. We recommend the use of explicitly batching operations likeinsertMultiple(),updateMultiple(), anddeleteMultiple()instead.
-
getCriteriaBuilder
- Specified by:
getCriteriaBuilderin interfaceEntityHandler- Returns:
- an instance of
HibernateCriteriaBuilder - Throws:
IllegalStateException- if the session has been closed- See Also:
-
doWork
Perform work using theConnectionunderlying 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
EntityHandler.runWithConnection(ConnectionConsumer)
-
doReturningWork
Perform work using theConnectionunderlying 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(Connection). - Throws:
HibernateException- Generally indicates wrappedSQLException- API Note:
- This method competes with the JPA-defined method
EntityHandler.callWithConnection(ConnectionFunction)
-
createEntityGraph
Create a new mutable instance ofEntityGraph, with only a root node, allowing programmatic definition of the graph from scratch.- Specified by:
createEntityGraphin interfaceEntityHandler- Parameters:
rootType- the root entity class of the graph- Since:
- 6.3
- See Also:
-
createEntityGraph
@Deprecated(since="8.0", forRemoval=true) @Nullable RootGraph<?> createEntityGraph(@Nonnull String graphName) Deprecated, for removal: This API element is subject to removal in a future version.UsegetEntityGraph(String)instead.Create a new mutable instance ofEntityGraph, based on a predefined named entity graph, allowing customization of the graph, or returnnullif there is no predefined graph with the given name.- Parameters:
graphName- the name of the graph- Since:
- 6.3
-
createEntityGraph
@Deprecated(since="8.0", forRemoval=true) @Nullable <T> RootGraph<T> createEntityGraph(@Nonnull Class<T> rootType, @Nonnull String graphName) Deprecated, for removal: This API element is subject to removal in a future version.UsegetEntityGraph(Class, String)instead.Create a new mutable instance ofEntityGraph, based on a predefined named entity graph, allowing customization of the graph, or returnnullif 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
-
getEntityGraph
Obtain a mutable copy of a predefined named entity graph.- Specified by:
getEntityGraphin interfaceEntityHandler- Parameters:
graphName- the name of the predefined named entity graph- Throws:
IllegalArgumentException- if there is no predefined graph with the given name- 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, by callinggetEntityGraph(Class, String), or by callingEntityManagerFactory.getNamedEntityGraphs(Class).
-
getEntityGraph
Obtain a mutable copy of a predefined named entity graph whose root type is exactly the given entity type.- Specified by:
getEntityGraphin interfaceEntityHandler- Parameters:
rootType- the root entity class of the graphgraphName- the name of the predefined named entity graph- Throws:
IllegalArgumentException- if there is no predefined graph with the given name, or if the graph with the given name does not have the given entity type as its root- Since:
- 8.0
- See Also:
-
getEntityGraphs
Retrieve all namedEntityGraphs with the given root entity type.- Specified by:
getEntityGraphsin interfaceEntityHandler- Since:
- 6.3
- See Also:
-
enableFilter
Enable the named filter for this current session.The returned
Filterobject 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
Filterinstance representing the enabled filter. - Throws:
UnknownFilterException- if there is no such filter- See Also:
-
getEnabledFilter
-
disableFilter
-
getFactory
The factory which created this session. -
inTransaction
Perform an action within the bounds of a transaction associated with this session.- Parameters:
action- a void function which accepts theTransaction- Since:
- 7.0
-
fromTransaction
Obtain a value within the bounds of a transaction associated with this session.- Parameters:
action- a function which accepts theTransactionand returns the value- Since:
- 7.0
-
statelessWithOptions
Obtain aStatelessSessionbuilder with the ability to copy certain information from this session.- Returns:
- the session builder
- Since:
- 7.2
-
sessionWithOptions
Obtain aSessionbuilder with the ability to copy certain information from this session.- Returns:
- the session builder
-
createQuery
Create an instance ofQueryfor the given HQL query or statement, without indicating the expected result type, if any, nor whether the query is a typed query which returns a result list, or an update, delete, or insert statement.- Specified by:
createQueryin interfaceEntityHandler
-
createNamedQuery
Create an instance ofQueryfor the given named query or statement, without indicating the expected result type, if any, nor whether the query is a typed query which returns a result list, or an update, delete, or insert statement.- Specified by:
createNamedQueryin interfaceEntityHandler
-
getEntityGraph(Class, String)instead.