Top Description Methods
org.hibernate

public Interface SharedSessionContract

extends QueryProducer, Closeable, Serializable
Known Direct Subinterfaces
org.hibernate.StatelessSession, org.hibernate.engine.spi.SharedSessionContractImplementor, org.hibernate.Session
Imports
java.io.Closeable, .Serializable, java.util.List, jakarta.persistence.EntityGraph, org.hibernate.graph.RootGraph, org.hibernate.jdbc.ReturningWork, .Work, org.hibernate.procedure.ProcedureCall, org.hibernate.query.QueryProducer, org.hibernate.query.criteria.HibernateCriteriaBuilder

Declares operations that are common between Session and StatelessSession.
Author
Steve Ebersole

Method Summary

Modifier and TypeMethod and Description
public Transaction

Returns:

a Transaction instance
beginTransaction
()

Begin a unit of work and return the associated Transaction object.

public void
close()

Redeclares java.io.Closeable.close.

End the session by releasing the JDBC connection and cleaning up.
public <T> RootGraph<T>
createEntityGraph(Class<T>
the root entity class of the graph
rootType
)

Create a new mutable EntityGraph with only a root node.

public RootGraph<?>
createEntityGraph(String
the name of the graph
graphName
)

Create a new mutable copy of the named EntityGraph, or return null if there is no graph with the given name.

public <T> RootGraph<T>
createEntityGraph(Class<T>
the root entity class of the graph
rootType
,
String
the name of the graph
graphName
)

Create a new mutable copy of the named EntityGraph, or return null if there is no graph with the given name.

public ProcedureCall

Returns:

The ProcedureCall
createNamedStoredProcedureQuery
(String
The name given to the template
name
)

Obtain a ProcedureCall based on a named template

public ProcedureCall

Returns:

The representation of the procedure call.
createStoredProcedureCall
(String
The name of the procedure.
procedureName
)

Create a ProcedureCall to a stored procedure.

public ProcedureCall

Returns:

The representation of the procedure call.
createStoredProcedureCall
(String
The name of the procedure.
procedureName
,
Class<?>...
The entity(s) to map the result on to.
resultClasses
)

Create a ProcedureCall to a stored procedure with the given result set entity mappings.

public ProcedureCall

Returns:

The representation of the procedure call.
createStoredProcedureCall
(String
The name of the procedure.
procedureName
,
String...
The explicit result set mapping(s) to use for mapping the results
resultSetMappings
)

Create a ProcedureCall to a stored procedure with the given result set entity mappings.

public ProcedureCall

Returns:

The representation of the procedure call.
createStoredProcedureQuery
(String
The name of the procedure.
procedureName
)

Create a ProcedureCall to a stored procedure.

public ProcedureCall

Returns:

The representation of the procedure call.
createStoredProcedureQuery
(String
The name of the procedure.
procedureName
,
Class<?>...
The entity(s) to map the result on to.
resultClasses
)

Create a ProcedureCall to a stored procedure with the given result set entity mappings.

public ProcedureCall

Returns:

The representation of the procedure call.
createStoredProcedureQuery
(String
The name of the procedure.
procedureName
,
String...
The explicit result set mapping(s) to use for mapping the results
resultSetMappings
)

Create a ProcedureCall to a stored procedure with the given result set entity mappings.

public default <
The type of the result returned from the work
T
>
T

Returns:

the result of calling ReturningWork#execute.
doReturningWork
(ReturningWork<T>
The work to be performed.
work
)

Perform work using the java.sql.Connection underlying by this session, and return a result.

public default void
doWork(Work
The work to be performed.
work
)

Perform work using the java.sql.Connection underlying by this session.

public HibernateCriteriaBuilder
public RootGraph<?>
getEntityGraph(String
the name of the graph
graphName
)

Retrieve the named EntityGraph as an immutable graph, or return null if there is no graph with the given name.

public <T> List<EntityGraph<? super T>>
getEntityGraphs(Class<T> entityClass)

Retrieve all named EntityGraphs with the given type.

public SessionFactory
getFactory()

The factory which created this session.

public Integer

Returns:

the current session-level JDBC batch size
getJdbcBatchSize
()

Get the session-level JDBC batch size for the current session.

public ProcedureCall

Returns:

The ProcedureCall
getNamedProcedureCall
(String
The name given to the template
name
)

Obtain a ProcedureCall based on a named template

public String

Returns:

The tenant identifier associated with this session, or null
getTenantIdentifier
()

Obtain the tenant identifier associated with this session.

public Object

Returns:

The tenant identifier associated with this session, or null
getTenantIdentifierValue
()

Obtain the tenant identifier associated with this session.

public Transaction

Returns:

a Transaction instance
getTransaction
()

Get the Transaction instance associated with this session.

public boolean

Returns:

boolean
isConnected
()

Check if the session is currently connected.

public boolean
isJoinedToTransaction()

Check if the session is joined to the current transaction.

public boolean

Returns:

boolean
isOpen
()

Check if the session is still open.

public void
joinTransaction()

Join the currently-active JTA transaction.

public void
setJdbcBatchSize(Integer
the new session-level JDBC batch size
jdbcBatchSize
)

Set the session-level JDBC batch size.

Inherited from org.hibernate.query.QueryProducer:
createMutationQuerycreateMutationQuerycreateMutationQuerycreateMutationQuerycreateNamedMutationQuerycreateNamedQuerycreateNamedQuerycreateNamedSelectionQuerycreateNamedSelectionQuerycreateNativeMutationQuerycreateNativeQuerycreateNativeQuerycreateNativeQuerycreateNativeQuerycreateNativeQuerycreateQuerycreateQuerycreateQuerycreateQuerycreateQuerycreateSelectionQuerycreateSelectionQuerycreateSelectionQuerygetNamedNativeQuerygetNamedNativeQuerygetNamedQuery

Method Detail

beginTransactionback to summary
public Transaction beginTransaction()

Begin a unit of work and return the associated Transaction 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:Transaction

a Transaction instance

See Also
getTransaction()
closeback to summary
public void close() throws HibernateException

Redeclares java.io.Closeable.close.

End the session by releasing the JDBC connection and cleaning up.

Exceptions
HibernateException:
Indicates problems cleaning up.
createEntityGraphback to summary
public <T> RootGraph<T> createEntityGraph(Class<T> rootType)

Create a new mutable EntityGraph with only a root node.

Parameters
rootType:Class<T>

the root entity class of the graph

Since
6.3
createEntityGraphback to summary
public RootGraph<?> createEntityGraph(String graphName)

Create a new mutable copy of the named EntityGraph, or return null if there is no graph with the given name.

Parameters
graphName:String

the name of the graph

Since
6.3
See Also
jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
createEntityGraphback to summary
public <T> RootGraph<T> createEntityGraph(Class<T> rootType, String graphName)

Create a new mutable copy of the named EntityGraph, or return null if there is no graph with the given name.

Parameters
rootType:Class<T>

the root entity class of the graph

graphName:String

the name of the graph

Exceptions
IllegalArgumentException:
if the graph with the given name does not have the given entity type as its root
Since
6.3
See Also
jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
createNamedStoredProcedureQueryback to summary
public ProcedureCall createNamedStoredProcedureQuery(String name)

Obtain a ProcedureCall based on a named template

Parameters
name:String

The name given to the template

Returns:ProcedureCall

The ProcedureCall

See Also
jakarta.persistence.NamedStoredProcedureQuery
createStoredProcedureCallback to summary
public ProcedureCall createStoredProcedureCall(String procedureName)

Create a ProcedureCall to a stored procedure.

Parameters
procedureName:String

The name of the procedure.

Returns:ProcedureCall

The representation of the procedure call.

createStoredProcedureCallback to summary
public ProcedureCall createStoredProcedureCall(String procedureName, Class<?>... resultClasses)

Create a ProcedureCall to a stored procedure with the given result set entity mappings. Each given class is considered a "root return".

Parameters
procedureName:String

The name of the procedure.

resultClasses:Class<?>[]

The entity(s) to map the result on to.

Returns:ProcedureCall

The representation of the procedure call.

createStoredProcedureCallback to summary
public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings)

Create a ProcedureCall to a stored procedure with the given result set entity mappings.

Parameters
procedureName:String

The name of the procedure.

resultSetMappings:String[]

The explicit result set mapping(s) to use for mapping the results

Returns:ProcedureCall

The representation of the procedure call.

createStoredProcedureQueryback to summary
public ProcedureCall createStoredProcedureQuery(String procedureName)

Create a ProcedureCall to a stored procedure.

Parameters
procedureName:String

The name of the procedure.

Returns:ProcedureCall

The representation of the procedure call.

createStoredProcedureQueryback to summary
public ProcedureCall createStoredProcedureQuery(String procedureName, Class<?>... resultClasses)

Create a ProcedureCall to a stored procedure with the given result set entity mappings. Each given class is considered a "root return".

Parameters
procedureName:String

The name of the procedure.

resultClasses:Class<?>[]

The entity(s) to map the result on to.

Returns:ProcedureCall

The representation of the procedure call.

createStoredProcedureQueryback to summary
public ProcedureCall createStoredProcedureQuery(String procedureName, String... resultSetMappings)

Create a ProcedureCall to a stored procedure with the given result set entity mappings.

Parameters
procedureName:String

The name of the procedure.

resultSetMappings:String[]

The explicit result set mapping(s) to use for mapping the results

Returns:ProcedureCall

The representation of the procedure call.

doReturningWorkback to summary
public default <T> T doReturningWork(ReturningWork<T> work) throws HibernateException

Perform work using the java.sql.Connection underlying by this session, and return a result.

Parameters
<T>
The type of the result returned from the work
work:ReturningWork<T>

The work to be performed.

Returns:T

the result of calling ReturningWork#execute.

Exceptions
HibernateException:
Generally indicates wrapped java.sql.SQLException
doWorkback to summary
public default void doWork(Work work) throws HibernateException

Perform work using the java.sql.Connection underlying by this session.

Parameters
work:Work

The work to be performed.

Exceptions
HibernateException:
Generally indicates wrapped java.sql.SQLException
getCriteriaBuilderback to summary
public HibernateCriteriaBuilder getCriteriaBuilder()

Obtain a HibernateCriteriaBuilder which may be used to construct criteria queries.

Returns:HibernateCriteriaBuilder

an instance of HibernateCriteriaBuilder

Exceptions
IllegalStateException:
if the session has been closed
See Also
SessionFactory#getCriteriaBuilder()
getEntityGraphback to summary
public RootGraph<?> getEntityGraph(String graphName)

Retrieve the named EntityGraph as an immutable graph, or return null if there is no graph with the given name.

Parameters
graphName:String

the name of the graph

Since
6.3
See Also
jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
getEntityGraphsback to summary
public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass)

Retrieve all named EntityGraphs with the given type.

Since
6.3
See Also
jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
getFactoryback to summary
public SessionFactory getFactory()

The factory which created this session.

getJdbcBatchSizeback to summary
public Integer getJdbcBatchSize()

Get the session-level JDBC batch size for the current session.

Returns:Integer

the current session-level JDBC batch size

Since
5.2
See Also
org.hibernate.boot.spi.SessionFactoryOptions#getJdbcBatchSize, org.hibernate.boot.SessionFactoryBuilder#applyJdbcBatchSize
getNamedProcedureCallback to summary
public ProcedureCall getNamedProcedureCall(String name)

Obtain a ProcedureCall based on a named template

Parameters
name:String

The name given to the template

Returns:ProcedureCall

The ProcedureCall

See Also
jakarta.persistence.NamedStoredProcedureQuery
getTenantIdentifierback to summary
public String getTenantIdentifier()

Obtain the tenant identifier associated with this session.

Returns:String

The tenant identifier associated with this session, or null

getTenantIdentifierValueback to summary
public Object getTenantIdentifierValue()

Obtain the tenant identifier associated with this session.

Returns:Object

The tenant identifier associated with this session, or null

Since
6.4
getTransactionback to summary
public Transaction getTransaction()

Get the Transaction instance associated with this session.

Returns:Transaction

a Transaction instance

See Also
jakarta.persistence.EntityManager#getTransaction()
isConnectedback to summary
public boolean isConnected()

Check if the session is currently connected.

Returns:boolean

boolean

isJoinedToTransactionback to summary
public boolean isJoinedToTransaction()

Check if the session is joined to the current transaction.

Since
6.2
See Also
joinTransaction(), jakarta.persistence.EntityManager#isJoinedToTransaction()
isOpenback to summary
public boolean isOpen()

Check if the session is still open.

Returns:boolean

boolean

joinTransactionback to summary
public void joinTransaction()

Join the currently-active JTA transaction.

Since
6.2
See Also
jakarta.persistence.EntityManager#joinTransaction()
setJdbcBatchSizeback to summary
public void setJdbcBatchSize(Integer jdbcBatchSize)

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:Integer

the new session-level JDBC batch size

Since
5.2
See Also
org.hibernate.cfg.AvailableSettings#STATEMENT_BATCH_SIZE, org.hibernate.boot.spi.SessionFactoryOptions#getJdbcBatchSize, org.hibernate.boot.SessionFactoryBuilder#applyJdbcBatchSize