Interface SharedSessionContractImplementor
- All Superinterfaces:
AutoCloseable, EntityHandler, JdbcSessionOwner, LobCreationContext, Serializable, SharedSessionContract, TransactionCoordinatorBuilder.Options, WrapperOptions
- All Known Subinterfaces:
EventSource, SessionImplementor, StatelessSessionImplementor
- All Known Implementing Classes:
SessionDelegatorBaseImpl
Session and
StatelessSession as used by other parts of Hibernate,
including implementors of Type, EntityPersister,
and CollectionPersister.
The Session, via this interface, implements:
-
JdbcSessionOwner, and so the session also acts as the orchestrator of a "JDBC session", and may be used to construct aJdbcCoordinator. -
TransactionCoordinatorBuilder.Options, allowing the session to control the creation of theTransactionCoordinatordelegate when it is passed as an argument toTransactionCoordinatorBuilder.buildTransactionCoordinator(TransactionCoordinatorOwner, TransactionCoordinatorBuilder.Options) -
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 ofJdbcType.
-
Nested Class Summary
Nested classes/interfaces inherited from interface LobCreationContext
LobCreationContext.Callback<T> -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the currentTransaction, or creates a new transaction if there is no transaction active.voidafterOperation(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.voidCalled after each operation on aScrollableResults, providing an opportunity for a stateless session to clear its temporary persistence context.default EventSourceCast this session toEventSourceif possible.default booleanautoFlushIfRequired(Set<String> querySpaces) detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flushbooleanautoFlushIfRequired(Set<String> querySpaces, boolean skipPreFlush) detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flushbooleanautoPreFlushIfRequired(QueryParameterBindings parameterBindings) 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.<T> TcallEntityLifecycleCallback(Supplier<T> callback) Call a Jakarta Persistence entity lifecycle callback.<T> TcallInterceptorCallback(Supplier<T> callback) Call a HibernateInterceptorcallback.default voidCheck whether the session is open, and if not: mark the current transaction, if any, for rollback only, and throw anIllegalStateException.voidcheckOpen(boolean markForRollbackIfClosed) Check whether the session is open, and if not: ifmarkForRollbackIfClosed = true, mark the current transaction, if any, for rollback only, and throw anIllegalStateException.default voidcheckTransactionNeededForUpdateOperation(String exceptionMessage) Check if an activeTransactionis available before performing an update operation against the database.<T> RootGraphImplementor<T> createEntityGraph(Class<T> rootType) Create a new mutable instance ofEntityGraph, with only a root node, allowing programmatic definition of the graph from scratch.createEntityGraph(String graphName) Deprecated.createMutationQuery(CriteriaStatement<?> criteriaStatement) Create aMutationQueryfrom the given update criteria treecreateMutationQuery(JpaCriteriaInsert<?> insert) Create aMutationQueryfrom the given insert criteria tree<R> SelectionQueryImplementor<R> createNamedQuery(String name, Class<R> resultClass) Create a typedQueryinstance for the given named query.<R> NativeQueryImplementor<R> createNamedQuery(String name, String resultSetMappingName) <R> NativeQueryImplementor<R> createNamedQuery(String name, String resultSetMappingName, Class<R> resultClass) default <R> NativeQueryImplementor<R> createNativeQuery(Class<R> resultClass, String sqlString) Synonym for SharedSessionContract.createNativeQuery(String,Class), offering generally easier readability for use code.createNativeQuery(String sql) Create aNativeQueryinstance for the given native SQL query.<T> NativeQueryImplementor<T> createNativeQuery(String sql, jakarta.persistence.sql.ResultSetMapping<T> resultSetMapping) <R> NativeQueryImplementor<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> NativeQueryImplementor<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.createNativeQuery(String sql, String resultSetMappingName) <R> NativeQueryImplementor<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> SelectionQueryImplementor<T> createQuery(CriteriaSelect<T> criteriaSelect) <R> SelectionQueryImplementor<R> createQuery(TypedQueryReference<R> typedQueryReference) Create a typedQueryinstance for the given typed query reference.default <R> SelectionQueryImplementor<R> createQuery(Class<R> resultClass, String hqlString) Synonym for SharedSessionContract.createQuery(String,Class), offering generally easier readability for use code.<T> SelectionQueryImplementor<T> createQuery(String hqlString, EntityGraph<T> entityGraph) <R> SelectionQueryImplementor<R> createQuery(String queryString, Class<R> resultClass) Create a typedQueryinstance for the given HQL query string and given query result type.createStatement(CriteriaStatement<?> criteriaStatement) voidflush()Flush this session.generateCollectionKey(CollectionPersister persister, Object key) Instantiate aCollectionKeywith the given key and for the collection represented by the givenCollectionPersister.generateEntityKey(Object id, EntityPersister persister) Instantiate anEntityKeywith the given id and for the entity represented by the givenEntityPersister.Access the transaction-scoped audit work queue for deferred audit row writes.The currentCacheTransactionSynchronizationassociated with this session.default IntegerGet the currently configured JDBC batch size, which might have been specified at either the session or factory level.getContextEntityIdentifier(Object object) Return the identifier of the persistent object, or null if it is not associated with this session.Obtain the full changeset context associated withgetCurrentChangesetIdentifier(), if the configured changeset supplier exposes one.The changeset id associated with the current unit of work, for use with temporal effectivity columns and with audit log changeset id columns.The currentTransactionobject associated with this session, if it has already been created, ornullotherwise.The default lock options associated with this session.Lock timeout specified on the SessionFactory via hint.Query timeout specified on the SessionFactory via hint.default DialectObtain theDialect.getEntityGraph(String graphName) Obtain a mutable copy of a predefined named entity graph.getEntityPersister(String entityName, Object object) Get theEntityPersisterfor the given entity instance.Get the entity instance associated with the givenEntityKey, calling theInterceptorif necessary.Get theSessionEventListenerManagerassociated with this session.Obtain anExceptionConverterfor reporting an error.<E extends Extension>
EgetExtension(Class<E> extension) Allows accessing session scoped extension storages of the particular session instance.Obtain the factory which created this session.Get the currentFlushModefor this session.Retrieves theInterceptorassociated with this session.Obtain theJdbcCoordinatorfor this session.Obtain theJdbcServicesfor the factory which created this session.Get theLoadQueryInfluencersassociated with this session.booleanGet the persistence context for this session.Similar togetPersistenceContext(), with two differences: this version performs better as it allows for inlining and probably better prediction, and it skips some checks of the current state of the session.default SharedSessionContractImplementorReturns this object, fulfilling the contract ofWrapperOptions.Wrap all state that lazy loading interceptors might need to manage association with this session, or to handle lazy loading after detachment via the UUID of the SessionFactory.default SessionFactoryImplementorObtain the factory which created this session.Obtain aUUIDwhich uniquely identifies this session.default ObjectObtain a "token" which uniquely identifies this session.Access to register callbacks for transaction completion processing.Access to registered callbacks for transaction completion processing.default TypeConfigurationObtain theTypeConfigurationfor the factory which created this session.guessEntityName(Object entity) Obtain an estimate of the entity name of the given entity instance, which is not involved in an association, using only theEntityNameResolver.immediateLoad(String entityName, Object id) Load an instance immediately.voidinitializeCollection(PersistentCollection<?> collection, boolean writing) Initialize the given collection (if not already initialized).instantiate(EntityPersister persister, Object id) Instantiate the entity class of the givenEntityPersister, initializing the new instance with the given identifier.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.booleanisClosed()Determines whether the session is closed.booleanbooleanbooleanAre entities and proxies loaded by this session read-only by default?default booleanDetermines if this session implementsEventSource.booleanbooleanIs the given entity managed by this session?default booleanDetermines whether the session is open or is waiting for auto-close.default booleanbooleanDoes this session have an active Hibernate transaction, or is it associated with a JTA transaction currently in progress?loadFromSecondLevelCache(EntityPersister persister, EntityKey entityKey, Object instanceToLoad, LockMode lockMode) Attempts to load the entity from the second-level cache.voidlock(String entityName, Object child, LockOptions lockOptions) Cascade the lock operation to the given child entity.voidMarks current transaction, if any, for rollback only.voidprepareForQueryExecution(boolean requiresTxn) Prepare for the execution of aQueryorProcedureCallvoidrunEntityLifecycleCallback(Runnable callback) Run a Jakarta Persistence entity lifecycle callback.voidrunInterceptorCallback(Runnable callback) Run a HibernateInterceptorcallback.voidsetCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled) voidsetCriteriaPlanCacheEnabled(boolean jpaCriteriaCacheEnabled) voidsetNativeJdbcParametersIgnored(boolean nativeJdbcParametersIgnored) 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, unwrapMethods inherited from interface JdbcSessionOwner
afterObtainConnection, afterTransactionBegin, afterTransactionCompletion, beforeReleaseConnection, beforeTransactionCompletion, flushBeforeTransactionCompletion, getEventMonitor, getJdbcBatchSize, getJdbcConnectionAccess, getJdbcSessionContext, getSqlExceptionHelper, getTransactionCoordinator, startTransactionBoundaryMethods inherited from interface LobCreationContext
execute, fromContextMethods inherited from interface SharedSessionContract
beginTransaction, close, createEntityGraph, createMutationQuery, createNamedMutationQuery, createNamedQuery, createNamedSelectionQuery, createNamedStatement, createNamedStoredProcedureQuery, createNativeMutationQuery, createNativeStatement, createQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery, createStatement, createStatement, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureQuery, createStoredProcedureQuery, createStoredProcedureQuery, disableFilter, doReturningWork, doWork, enableFilter, find, find, fromTransaction, get, get, getCacheMode, getCriteriaBuilder, getEnabledFilter, getEntityGraph, getEntityGraphs, getJdbcBatchSize, getNamedProcedureCall, getTenantIdentifier, getTenantIdentifierValue, getTransaction, inTransaction, isConnected, isJoinedToTransaction, isOpen, joinTransaction, sessionWithOptions, setCacheMode, setJdbcBatchSize, statelessWithOptionsMethods inherited from interface TransactionCoordinatorBuilder.Options
shouldAutoJoinTransactionMethods inherited from interface WrapperOptions
getJdbcTimeZone, getJsonFormatMapper, getLobCreator, getPreferredSqlTypeCodeForBoolean, getXmlFormatMapper, useLanguageTagForLocale, useStreamForLobBinding
-
Method Details
-
getFactory
Obtain the factory which created this session.- Specified by:
getFactoryin interfaceSharedSessionContract
-
getSessionFactory
Obtain the factory which created this session.- Specified by:
getSessionFactoryin interfaceWrapperOptions
-
getTypeConfiguration
Obtain theTypeConfigurationfor the factory which created this session.- Specified by:
getTypeConfigurationin interfaceWrapperOptions
-
getDialect
Obtain theDialect.- Specified by:
getDialectin interfaceWrapperOptions
-
getEventListenerManager
Get theSessionEventListenerManagerassociated with this session. -
getPersistenceContext
Get the persistence context for this session.See
getPersistenceContextInternal()for a faster alternative.- Implementation Note:
- This method is not extremely fast: if you need to
call the
PersistenceContextmultiple times, prefer keeping a reference to it instead of invoking this method multiple times.
-
getJdbcCoordinator
Obtain theJdbcCoordinatorfor this session. -
getJdbcServices
Obtain theJdbcServicesfor the factory which created this session. -
getSessionIdentifier
-
getSession
Returns this object, fulfilling the contract ofWrapperOptions.- Specified by:
getSessionin interfaceWrapperOptions
-
getSessionToken
Obtain a "token" which uniquely identifies this session. -
isClosed
boolean isClosed()Determines whether the session is closed.- Returns:
trueif the session is closed;falseotherwise.- API Note:
- Provided separately from
SharedSessionContract.isOpen()as this method does not attempt any JTA synchronization registration, whereasSharedSessionContract.isOpen()does. This one is better for most internal purposes.
-
isOpenOrWaitingForAutoClose
default boolean isOpenOrWaitingForAutoClose()Determines whether the session is open or is waiting for auto-close.- Returns:
trueif the session is closed, or if it's waiting for auto-close;falseotherwise.
-
checkOpen
default void checkOpen()Check whether the session is open, and if not:- mark the current transaction, if any, for rollback only, and
- throw an
IllegalStateException. (JPA specifies this exception type.)
-
checkOpen
void checkOpen(boolean markForRollbackIfClosed) Check whether the session is open, and if not:- if
markForRollbackIfClosed = true, mark the current transaction, if any, for rollback only, and - throw an
IllegalStateException. (JPA specifies this exception type.)
- if
-
runEntityLifecycleCallback
Run a Jakarta Persistence entity lifecycle callback. -
callEntityLifecycleCallback
-
runInterceptorCallback
Run a HibernateInterceptorcallback. -
callInterceptorCallback
Call a HibernateInterceptorcallback. -
prepareForQueryExecution
void prepareForQueryExecution(boolean requiresTxn) Prepare for the execution of aQueryorProcedureCall -
markForRollbackOnly
void markForRollbackOnly()Marks current transaction, if any, for rollback only. -
getCacheTransactionSynchronization
CacheTransactionSynchronization getCacheTransactionSynchronization()The currentCacheTransactionSynchronizationassociated with this session. This may benullif the session is not currently associated with an active transaction. -
getCurrentChangesetIdentifier
Object getCurrentChangesetIdentifier()The changeset id associated with the current unit of work, for use with temporal effectivity columns and with audit log changeset id columns. -
getCurrentChangesetContext
Obtain the full changeset context associated withgetCurrentChangesetIdentifier(), if the configured changeset supplier exposes one.This is used by graph-queue audit execution to capture changelog state before materializing audit bind plans. Suppliers which only produce a scalar changeset identifier return
null. -
isTransactionInProgress
boolean isTransactionInProgress()Does this session have an active Hibernate transaction, or is it associated with a JTA transaction currently in progress? -
checkTransactionNeededForUpdateOperation
Check if an activeTransactionis available before performing an update operation against the database.If an active transaction is necessary, but no transaction is active, a
TransactionRequiredExceptionis raised.- Parameters:
exceptionMessage- the message to use for theTransactionRequiredException
-
accessTransaction
Retrieves the currentTransaction, or creates a new transaction if there is no transaction active.This method is primarily for internal or integrator use.
- Returns:
- the
Transaction
-
getCurrentTransaction
The currentTransactionobject associated with this session, if it has already been created, ornullotherwise.- Since:
- 7.2
-
getTransactionCompletionCallbacks
Access to register callbacks for transaction completion processing.- Since:
- 7.2
-
getTransactionCompletionCallbacksImplementor
@Incubating @Nonnull TransactionCompletionCallbacksImplementor getTransactionCompletionCallbacksImplementor()Access to registered callbacks for transaction completion processing.- Since:
- 7.2
-
getAuditWorkQueue
Access the transaction-scoped audit work queue for deferred audit row writes. Lazily initialized on first access.- Since:
- 7.4
-
generateEntityKey
Instantiate anEntityKeywith the given id and for the entity represented by the givenEntityPersister.When operating in a temporal context, this will automatically create a
TemporalEntityKeythat includes the transaction identifier.- Parameters:
id- The entity idpersister- The entity persister- Returns:
- The entity key
-
generateCollectionKey
@Nonnull CollectionKey generateCollectionKey(@Nonnull CollectionPersister persister, @Nonnull Object key) Instantiate aCollectionKeywith the given key and for the collection represented by the givenCollectionPersister.When operating in a temporal context, this will automatically create a
TemporalCollectionKeythat includes the transaction identifier.- Parameters:
persister- The collection persisterkey- The collection key (owner FK)- Returns:
- The collection key
-
getInterceptor
Interceptor getInterceptor()Retrieves theInterceptorassociated with this session. -
initializeCollection
void initializeCollection(@Nonnull PersistentCollection<?> collection, boolean writing) throws HibernateException Initialize the given collection (if not already initialized).- Throws:
HibernateException
-
internalLoad
Object internalLoad(@Nonnull String entityName, @Nonnull 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
nullable = false, this method may create a new proxy or return an existing proxy; if it does not exist, an exception is thrown. - When
nullable = true, the method does not create new proxies, though it might return an existing proxy; if it does not exist, anullvalue is returned.
When
eager = true, the object is eagerly fetched from the database.- Throws:
HibernateException
- When
-
immediateLoad
-
getEntityPersister
Get theEntityPersisterfor the given entity instance.- Parameters:
entityName- optional entity nameobject- the entity instance
-
getEntityUsingInterceptor
Get the entity instance associated with the givenEntityKey, calling theInterceptorif necessary. -
getContextEntityIdentifier
-
bestGuessEntityName
-
guessEntityName
Obtain an estimate of the entity name of the given entity instance, which is not involved in an association, using only theEntityNameResolver. -
instantiate
Instantiate the entity class of the givenEntityPersister, initializing the new instance with the given identifier. -
isDefaultReadOnly
boolean isDefaultReadOnly()Are entities and proxies loaded by this session read-only by default? -
isIdentifierRollbackEnabled
boolean isIdentifierRollbackEnabled() -
setCriteriaCopyTreeEnabled
void setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled) -
isCriteriaCopyTreeEnabled
boolean isCriteriaCopyTreeEnabled() -
setCriteriaPlanCacheEnabled
void setCriteriaPlanCacheEnabled(boolean jpaCriteriaCacheEnabled) -
isCriteriaPlanCacheEnabled
boolean isCriteriaPlanCacheEnabled() -
getNativeJdbcParametersIgnored
boolean getNativeJdbcParametersIgnored() -
setNativeJdbcParametersIgnored
void setNativeJdbcParametersIgnored(boolean nativeJdbcParametersIgnored) -
getHibernateFlushMode
-
flush
void flush()Flush this session. -
isEventSource
default boolean isEventSource()Determines if this session implementsEventSource.Only stateful session are sources of events. If this object is a stateless session, this method return
false. -
asEventSource
Cast this session toEventSourceif possible.Only stateful session are sources of events. If this object is a stateless session, this method throws.
- Throws:
ClassCastException- if the cast is not possible
-
isStateless
default boolean isStateless()- API Note:
- Essentially, whether casting this session to StatelessSessionImplementor will succeed.
-
afterScrollOperation
void afterScrollOperation()Called after each operation on aScrollableResults, providing an opportunity for a stateless session to clear its temporary persistence context. For a stateful session, this method does nothing. -
getLoadQueryInfluencers
Get theLoadQueryInfluencersassociated with this session.- Returns:
- the
LoadQueryInfluencersassociated with this session; should never be null.
-
getDefaultLockOptions
LockOptions getDefaultLockOptions()The default lock options associated with this session. -
getDefaultLockTimeout
-
getDefaultTimeout
-
getExceptionConverter
Obtain anExceptionConverterfor reporting an error.The converter associated to a session might be lazily initialized, so only invoke this getter when there's an actual need to use it.
- Returns:
- the ExceptionConverter for this Session.
-
getConfiguredJdbcBatchSize
-
getPersistenceContextInternal
Similar togetPersistenceContext(), with two differences:- this version performs better as it allows for inlining and probably better prediction, and
- it skips some checks of the current state of the session.
- Returns:
- the
PersistenceContextassociated to this session.
-
isManaged
Is the given entity managed by this session?- Returns:
- true if this is a stateful session and the entity belongs to its persistence context and was not removed
-
autoFlushIfRequired
-
autoFlushIfRequired
detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush- Parameters:
querySpaces- the tables named in the query.skipPreFlush- seeAutoFlushEvent.isSkipPreFlush()- Returns:
- true if flush is required, false otherwise.
-
autoPreFlushIfRequired
-
afterOperation
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.- Parameters:
success-trueif the operation a success
-
lock
-
loadFromSecondLevelCache
@Incubating Object loadFromSecondLevelCache(@Nonnull EntityPersister persister, @Nonnull EntityKey entityKey, @Nullable Object instanceToLoad, @Nonnull LockMode lockMode) Attempts to load the entity from the second-level cache.- Parameters:
persister- The persister for the entity being requested for loadentityKey- The entity keyinstanceToLoad- The instance that is being initialized, or nulllockMode- The lock mode- Returns:
- The entity from the second-level cache, or null.
- Since:
- 7.0
-
getSessionAssociationMarkers
Wrap all state that lazy loading interceptors might need to manage association with this session, or to handle lazy loading after detachment via the UUID of the SessionFactory. N.B. this captures the current Session, however it can get updated to a null session (for detached entities) or updated to a different Session. -
createEntityGraph
Description copied from interface:SharedSessionContractCreate a new mutable instance ofEntityGraph, with only a root node, allowing programmatic definition of the graph from scratch.- Specified by:
createEntityGraphin interfaceEntityHandler- Specified by:
createEntityGraphin interfaceSharedSessionContract- Parameters:
rootType- the root entity class of the graph- See Also:
-
createEntityGraph
Deprecated.Description copied from interface:SharedSessionContractCreate 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.- Specified by:
createEntityGraphin interfaceSharedSessionContract- Parameters:
graphName- the name of the graph
-
getEntityGraph
Description copied from interface:SharedSessionContractObtain a mutable copy of a predefined named entity graph.- Specified by:
getEntityGraphin interfaceEntityHandler- Specified by:
getEntityGraphin interfaceSharedSessionContract- Parameters:
graphName- the name of the predefined named entity graph- See Also:
-
createQuery
@Nonnull <R> SelectionQueryImplementor<R> createQuery(@Nonnull String queryString, @Nonnull Class<R> resultClass) Description copied from interface:SharedSessionContractCreate 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- Specified by:
createQueryin interfaceSharedSessionContract- 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> SelectionQueryImplementor<R> createQuery(@Nonnull Class<R> resultClass, @Nonnull String hqlString) Description copied from interface:SharedSessionContractSynonym for SharedSessionContract.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();- Specified by:
createQueryin interfaceSharedSessionContract
-
createQuery
@Nonnull <R> SelectionQueryImplementor<R> createQuery(@Nonnull TypedQueryReference<R> typedQueryReference) Description copied from interface:SharedSessionContractCreate a typedQueryinstance for the given typed query reference.- Specified by:
createQueryin interfaceEntityHandler- Specified by:
createQueryin interfaceSharedSessionContract- Parameters:
typedQueryReference- the type query reference- Returns:
- The
Queryinstance for execution - See Also:
-
createNativeQuery
@Nonnull <R> NativeQueryImplementor<R> createNativeQuery(@Nonnull String sqlString, @Nonnull Class<R> resultClass) Description copied from interface:SharedSessionContractCreate 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- Specified by:
createNativeQueryin interfaceSharedSessionContract- 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
@Nonnull default <R> NativeQueryImplementor<R> createNativeQuery(@Nonnull Class<R> resultClass, @Nonnull String sqlString) Description copied from interface:SharedSessionContractSynonym for SharedSessionContract.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();- Specified by:
createNativeQueryin interfaceSharedSessionContract
-
createNativeQuery
@Nonnull <R> NativeQueryImplementor<R> createNativeQuery(@Nonnull String sqlString, @Nonnull Class<R> resultClass, @Nonnull String tableAlias) Description copied from interface:SharedSessionContractCreate 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).- Specified by:
createNativeQueryin interfaceSharedSessionContract- 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
@Nonnull <R> NativeQueryImplementor<R> createNativeQuery(@Nonnull String sqlString, @Nonnull String resultSetMappingName, @Nonnull Class<R> resultClass) Description copied from interface:SharedSessionContractCreate 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.- Specified by:
createNativeQueryin interfaceSharedSessionContract- Parameters:
sqlString- The native (SQL) query stringresultSetMappingName- The explicit result mapping name- Returns:
- The
NativeQueryinstance for manipulation and execution - See Also:
-
createNamedQuery
@Nonnull <R> SelectionQueryImplementor<R> createNamedQuery(@Nonnull String name, @Nonnull Class<R> resultClass) Description copied from interface:SharedSessionContractCreate a typedQueryinstance for the given named query. The named query might be defined in HQL or in native SQL.- Specified by:
createNamedQueryin interfaceEntityHandler- Specified by:
createNamedQueryin interfaceSharedSessionContract- Parameters:
name- the name of a query defined in metadataresultClass- the type of the query result- Returns:
- The
Queryinstance for manipulation and execution - See Also:
-
createNamedQuery
@Nonnull <R> NativeQueryImplementor<R> createNamedQuery(@Nonnull String name, @Nonnull String resultSetMappingName) - Specified by:
createNamedQueryin interfaceSharedSessionContract
-
createNamedQuery
@Nonnull <R> NativeQueryImplementor<R> createNamedQuery(@Nonnull String name, @Nonnull String resultSetMappingName, @Nonnull Class<R> resultClass) - Specified by:
createNamedQueryin interfaceSharedSessionContract
-
createQuery
Description copied from interface:SharedSessionContract- Specified by:
createQueryin interfaceEntityHandler- Specified by:
createQueryin interfaceSharedSessionContract- See Also:
-
createMutationQuery
@Nonnull MutationQueryImplementor<?> createMutationQuery(@Nonnull CriteriaStatement<?> criteriaStatement) Description copied from interface:SharedSessionContractCreate aMutationQueryfrom the given update criteria tree- Specified by:
createMutationQueryin interfaceSharedSessionContract
-
createStatement
Description copied from interface:SharedSessionContract- Specified by:
createStatementin interfaceEntityHandler- Specified by:
createStatementin interfaceSharedSessionContract- See Also:
-
createMutationQuery
Description copied from interface:SharedSessionContractCreate aMutationQueryfrom the given insert criteria tree- Specified by:
createMutationQueryin interfaceSharedSessionContract
-
createQuery
@Nonnull <T> SelectionQueryImplementor<T> createQuery(@Nonnull String hqlString, @Nonnull EntityGraph<T> entityGraph) - Specified by:
createQueryin interfaceEntityHandler- Specified by:
createQueryin interfaceSharedSessionContract- See Also:
-
createNativeQuery
Description copied from interface:SharedSessionContractCreate aNativeQueryinstance for the given native SQL query.- Specified by:
createNativeQueryin interfaceEntityHandler- Specified by:
createNativeQueryin interfaceSharedSessionContract- Parameters:
sql- The native (SQL) query string- Returns:
- The
NativeQueryinstance for manipulation and execution - See Also:
-
createNativeQuery
@Nonnull NativeQueryImplementor createNativeQuery(@Nonnull String sql, @Nonnull String resultSetMappingName) - Specified by:
createNativeQueryin interfaceEntityHandler- Specified by:
createNativeQueryin interfaceSharedSessionContract
-
createNativeQuery
@Nonnull <T> NativeQueryImplementor<T> createNativeQuery(@Nonnull String sql, @Nonnull jakarta.persistence.sql.ResultSetMapping<T> resultSetMapping) - Specified by:
createNativeQueryin interfaceEntityHandler- Specified by:
createNativeQueryin interfaceSharedSessionContract
-
getExtension
Allows accessing session scoped extension storages of the particular session instance.Extensions first had to be registered with the
SessionFactory- Type Parameters:
E- The type of the extension storage.- Parameters:
extension- The extension storage attached to the current session. if the current session does not yet have the particular storage type attached to this session.
-