Class SessionLazyDelegator
- All Implemented Interfaces:
EntityHandler, EntityManager, Serializable, AutoCloseable, Session, SharedSessionContract
Supplier.
When the decorated instance is readily available, one
should prefer using SessionDelegatorBaseImpl.
Another difference with SessionDelegatorBaseImpl is that this type only implements Session.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface EntityManager
EntityManager.CreationOption, EntityManager.Option -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListeners(SessionEventListener... listeners) Add one or more listeners to the SessionvoidaddOption(EntityManager.Option option) Begin a unit of work and return the associatedTransactionobject.<T> IdentifierLoadAccess<T> Create anIdentifierLoadAccessinstance to retrieve an instance of the given entity type by its primary key.<T> IdentifierLoadAccess<T> Create anIdentifierLoadAccessinstance to retrieve an instance of the named entity type by its primary key.<T> MultiIdentifierLoadAccess<T> byMultipleIds(Class<T> entityClass) Create aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the given entity type by their primary key values, using batching.<T> MultiIdentifierLoadAccess<T> byMultipleIds(String entityName) Create aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the named entity type by their primary key values, using batching.<T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(Class<T> entityClass) Deprecated.<T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(String entityName) Deprecated.<T> NaturalIdLoadAccess<T> byNaturalId(Class<T> entityClass) Deprecated.<T> NaturalIdLoadAccess<T> byNaturalId(String entityName) Deprecated.<T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(Class<T> entityClass) Deprecated.<T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(String entityName) Deprecated.<C,T> T callWithConnection(ConnectionFunction<C, T> function) voidCancel the execution of the current query.voidclear()Completely clear the persistence context.voidclose()End the session by releasing the JDBC connection and cleaning up.booleanbooleanDetermine if the given entity is associated with this session.<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.RootGraph<?> createEntityGraph(String graphName) Deprecated.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.createNativeQuery(String sqlString) Deprecated.<T> TypedQuery<T> createNativeQuery(String sql, jakarta.persistence.sql.ResultSetMapping<T> resultSetMapping) createNativeQuery(String sqlString, Class 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.createNativeQuery(String sqlString, String resultSetMappingName) Deprecated.<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> selectQuery) createQuery(CriteriaStatement<?> criteriaStatement) <R> SelectionQuery<R> createQuery(TypedQueryReference<R> typedQueryReference) Create a typedQueryinstance for the given typed query reference.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 query, 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.voidRemove this instance from the session cache.voiddisableFetchProfile(String name) Disable the fetch profile with the given name in this session.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.voidenableFetchProfile(String name) Enable the fetch profile with the given name in this session.enableFilter(String filterName) Enable the named filter for this current session.voidRemove this instance from the session cache.<T> Tfind(EntityGraph<T> entityGraph, Object primaryKey, FindOption... options) <T> TReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.<T> Tfind(Class<T> entityClass, Object primaryKey, FindOption... options) The option
KeyType.NATURALspecifies that the given id should be interpreted as a natural id.<T> T<T> Tfind(String entityName, Object primaryKey, FindOption... options) Corollary toEntityHandler.find(Class,Object,FindOption...)for dynamic models.<E> List<E> findMultiple(EntityGraph<E> entityGraph, List<?> ids, FindOption... options) Return the persistent instances of the root entity of the givenEntityGraphwith the given identifiers as a list, fetching the associations specified by the graph, which is interpreted as a load graph.<E> List<E> findMultiple(Class<E> entityType, List<?> ids, FindOption... options) Return the persistent instances of the given entity class with the given identifiers as a list.voidflush()Force this session to flush.<T> Tget(EntityGraph<T> entityGraph, Object key, FindOption... findOptions) <T> T<T> Tget(Class<T> entityType, Object key, FindOption... findOptions) <T> TReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.<T> Tget(Class<T> entityType, Object id, LockOptions lockOptions) Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.get(String entityName, Object key, FindOption... findOptions) Form ofSharedSessionContract.find(String,Object,FindOption...)throwingEntityNotFoundExceptionif no entity exists for that id rather than returning null.Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.get(String entityName, Object id, LockOptions lockOptions) Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.Get the current cache mode for this session.The JPA-definedCacheRetrieveMode.The JPA-definedCacheStoreMode.getCurrentLockMode(Object object) Determine the current lock mode held on the given managed instance associated with this session.Deprecated.getEnabledFilter(String filterName) Retrieve a currently enabled filter by name.<T> RootGraph<T> getEntityGraph(Class<T> entityClass, String name) 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.getEntityName(Object object) Return the entity name for the given persistent entity.The factory which created this session.intGet the maximum batch size for batch fetching associations by id in this session.Get the current JPA flush mode for this session.Get the current flush mode for this session.getIdentifier(Object object) Return the identifier value of the given entity associated with this session.Get the session-level JDBC batch size for the current session.getLockMode(Object entity) Collection<?> Obtain the collection of all managed entities which belong to this persistence context.<E> Collection<E> getManagedEntities(EntityType<E> entityType) Obtain a collection of all managed entities of the given type which belong to this persistence context.<E> Collection<E> getManagedEntities(Class<E> entityType) Obtain a collection of all managed entities of the given type which belong to this persistence context.Collection<?> getManagedEntities(String entityName) Obtain a collection of all managed instances of the entity type with the given entity name which belong to this persistence context.<T> List<T> getMultiple(EntityGraph<T> entityGraph, List<?> keys, FindOption... findOptions) <T> List<T> getMultiple(Class<T> entityType, List<?> keys, FindOption... findOptions) getNamedNativeQuery(String name) Deprecated.getNamedProcedureCall(String name) Obtain aProcedureCallbased on a named template<T> TgetReference(Class<T> entityType, Object id) Return a reference to the persistent instance with the given class and identifier, making the assumption that the instance is still persistent in the database.<T> TgetReference(Class<T> entityType, Object key, KeyType keyType) Return a reference to the persistent instance of the given entity type with the given key, which is interpreted according to the givenKeyType, making the assumption that the instance is still persistent in the database.getReference(String entityName, Object id) Return a reference to the persistent instance of the given named entity with the given identifier, making the assumption that the instance is still persistent in the database.<T> TgetReference(T object) Return a reference to the persistent instance with the same identity as the given instance, which might be detached, making the assumption that the instance is still persistent in the database.Get the session factory which created this session.Get the statistics for this session.Obtain the tenant identifier associated with this session, as a string.Obtain the tenant identifier associated with this session.Get theTransactioninstance associated with this session.booleanCheck if the session is currently connected.booleanWill entities and proxies that are loaded into this session be made read-only by default?booleanisDirty()Whether this session contains any changes which must be synchronized with the database.booleanisFetchProfileEnabled(String name) Is the fetch profile with the given name enabled in this session?booleanCheck if the session is joined to the current transaction.booleanisOpen()Check if the session is still open.booleanisReadOnly(Object entityOrProxy) Is the specified entity or proxy read-only?booleanDetermine if subselect fetching is enabled in this session.voidJoin the currently active JTA transaction.voidRead the persistent state associated with the given identifier into the given transient instance.voidlock(Object entity, LockModeType lockMode) voidlock(Object entity, LockModeType lockMode, LockOption... options) voidvoidObtain the specified lock level on the given managed instance associated with this session.voidlock(Object object, LockMode lockMode, LockOption... lockOptions) Obtain the specified lock level on the given managed instance associated with this session, applying any other specified options.voidlock(Object object, LockOptions lockOptions) Obtain a lock on the given managed instance associated with this session, using the given lock options.<T> TCopy the state of the given object onto the persistent object with the same identifier.<T> Tmerge(T object) Copy the state of the given object onto the persistent object with the same identifier.<T> Tmerge(T object, EntityGraph<? super T> loadGraph) Copy the state of the given object onto the persistent object with the same identifier.voidMake a transient instance persistent and mark it for later insertion in the database.voidMake a transient instance persistent and mark it for later insertion in the database.voidReread the state of the given managed instance associated with this session from the underlying database.voidvoidrefresh(Object entity, RefreshOption... options) voidvoidrefresh(Object object, LockOptions lockOptions) Reread the state of the given managed instance from the underlying database, obtaining the givenLockMode.voidMark a persistence instance associated with this session for removal from the underlying database.<C> voidrunWithConnection(ConnectionConsumer<C> action) Obtain aSessionbuilder with the ability to copy certain information from this session.voidsetCacheMode(CacheMode cacheMode) Set the current cache mode for this session.voidsetCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) Enable or disable reads from the second-level cache.voidsetCacheStoreMode(CacheStoreMode cacheStoreMode) Enable or disable writes to the second-level cache.voidsetDefaultReadOnly(boolean readOnly) Change the default for entities and proxies loaded into this session from modifiable to read-only mode, or from read-only to modifiable mode.voidsetFetchBatchSize(int batchSize) Set the maximum batch size for batch fetching associations by id in this session.voidsetFlushMode(FlushModeType flushMode) Set the current JPA flush mode for this session.voidsetHibernateFlushMode(FlushMode flushMode) Set the current flush mode for this session.voidsetJdbcBatchSize(Integer jdbcBatchSize) Set the session-level JDBC batch size.voidsetProperty(String propertyName, Object value) Set a hint.voidsetReadOnly(Object entityOrProxy, boolean readOnly) Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.voidsetSubselectFetchingEnabled(boolean enabled) Enable or disable subselect fetching in this session.Obtain aStatelessSessionbuilder with the ability to copy certain information from this session.<T> TMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SharedSessionContract
createNativeQuery, createQuery, find, fromTransaction, get, inTransaction
-
Constructor Details
-
SessionLazyDelegator
-
-
Method Details
-
getFactory
Description copied from interface:SharedSessionContractThe factory which created this session.- Specified by:
getFactoryin interfaceSharedSessionContract
-
flush
public void flush()Description copied from interface:SessionForce this session to flush. Must be called at the end of a unit of work, before the transaction is committed. Depending on the current flush mode, the session might automatically flush when
EntityTransaction.commit()is called, and it is not necessary to call this method directly.Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
- Specified by:
flushin interfaceEntityManager- Specified by:
flushin interfaceSession
-
setFlushMode
Description copied from interface:SessionSet the current JPA flush mode for this session.
Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory. The current flush mode determines when the session is automatically flushed.
- Specified by:
setFlushModein interfaceEntityManager- Specified by:
setFlushModein interfaceSession- Parameters:
flushMode- the newFlushModeType- See Also:
-
setHibernateFlushMode
Description copied from interface:SessionSet the current flush mode for this session.
Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory. The current flush mode determines when the session is automatically flushed.
The default flush mode is sometimes unnecessarily aggressive. For a logically "read only" session, it's reasonable to set the session's flush mode to
FlushMode.MANUALat the start of the session in order to avoid some unnecessary work.Note that
FlushModedefines more options thanFlushModeType.- Specified by:
setHibernateFlushModein interfaceSession- Parameters:
flushMode- the newFlushMode
-
getFlushMode
Description copied from interface:SessionGet the current JPA flush mode for this session.- Specified by:
getFlushModein interfaceEntityManager- Specified by:
getFlushModein interfaceSession- Returns:
- the
FlushModeTypecurrently in effect - See Also:
-
getHibernateFlushMode
Description copied from interface:SessionGet the current flush mode for this session.- Specified by:
getHibernateFlushModein interfaceSession- Returns:
- the
FlushModecurrently in effect
-
setCacheMode
Description copied from interface:SessionSet the current cache mode for this session.
The cache mode determines the manner in which this session can interact with the second level cache.
- Specified by:
setCacheModein interfaceSession- Specified by:
setCacheModein interfaceSharedSessionContract- Parameters:
cacheMode- the new cache mode
-
setCacheRetrieveMode
Description copied from interface:SessionEnable or disable reads from the second-level cache.- Specified by:
setCacheRetrieveModein interfaceEntityHandler- Specified by:
setCacheRetrieveModein interfaceSession- Parameters:
cacheRetrieveMode- a JPA-definedCacheRetrieveMode- See Also:
-
setCacheStoreMode
Description copied from interface:SessionEnable or disable writes to the second-level cache.- Specified by:
setCacheStoreModein interfaceEntityHandler- Specified by:
setCacheStoreModein interfaceSession- Parameters:
cacheStoreMode- a JPA-definedCacheStoreMode- See Also:
-
getCacheStoreMode
Description copied from interface:SessionThe JPA-definedCacheStoreMode.- Specified by:
getCacheStoreModein interfaceEntityHandler- Specified by:
getCacheStoreModein interfaceSession- See Also:
-
getCacheRetrieveMode
Description copied from interface:SessionThe JPA-definedCacheRetrieveMode.- Specified by:
getCacheRetrieveModein interfaceEntityHandler- Specified by:
getCacheRetrieveModein interfaceSession- See Also:
-
addOption
- Specified by:
addOptionin interfaceEntityManager
-
getOptions
- Specified by:
getOptionsin interfaceEntityManager
-
getCacheMode
Description copied from interface:SessionGet the current cache mode for this session.- Specified by:
getCacheModein interfaceSession- Specified by:
getCacheModein interfaceSharedSessionContract- Returns:
- the current cache mode
-
getSessionFactory
Description copied from interface:SessionGet the session factory which created this session.- Specified by:
getSessionFactoryin interfaceSession- Returns:
- the session factory
- See Also:
-
cancelQuery
public void cancelQuery()Description copied from interface:SessionCancel the execution of the current query.
This is the sole method on session which may be safely called from another thread.
- Specified by:
cancelQueryin interfaceSession
-
isDirty
public boolean isDirty()Description copied from interface:SessionWhether this session contains any changes which must be synchronized with the database. In other words, would any DML operations be executed if we flushed this session? -
isDefaultReadOnly
public boolean isDefaultReadOnly()Description copied from interface:SessionWill entities and proxies that are loaded into this session be made read-only by default?
To determine the read-only/modifiable setting for a particular entity or proxy use
Session.isReadOnly(Object).- Specified by:
isDefaultReadOnlyin interfaceSession- Returns:
true, loaded entities/proxies will be made read-only by default;false, loaded entities/proxies will be made modifiable by default.- See Also:
-
setDefaultReadOnly
public void setDefaultReadOnly(boolean readOnly) Description copied from interface:SessionChange the default for entities and proxies loaded into this session from modifiable to read-only mode, or from read-only to modifiable mode.
Read-only entities are not dirty-checked, and snapshots of persistent state are not maintained. Read-only entities can be modified, but a modification to a field of a read-only entity is not made persistent.
When a proxy is initialized, the loaded entity will have the same read-only/modifiable setting as the uninitialized proxy, regardless of the current default read-only mode of the session.
To change the read-only/modifiable setting for a particular entity or proxy that already belongs to this session, use
Session.setReadOnly(Object,boolean).To override the default read-only mode of the current session for all entities and proxies returned by a given
Query, useSelectionQuery.setReadOnly(boolean).Every instance of an immutable entity is loaded in read-only mode.
- Specified by:
setDefaultReadOnlyin interfaceSession- Parameters:
readOnly-true, the default for loaded entities/proxies is read-only;false, the default for loaded entities/proxies is modifiable- See Also:
-
getIdentifier
Description copied from interface:SessionReturn the identifier value of the given entity associated with this session. An exception is thrown if the given entity instance is transient or detached in relation to this session.- Specified by:
getIdentifierin interfaceSession- Parameters:
object- a persistent instance associated with this session- Returns:
- the identifier
-
contains
Description copied from interface:SessionDetermine if the given entity is associated with this session. -
detach
Description copied from interface:SessionRemove this instance from the session cache. Changes to the instance will not be synchronized with the database. This operation cascades to associated instances if the association is mapped withCascadeType.DETACH.- Specified by:
detachin interfaceEntityManager- Specified by:
detachin interfaceSession- Parameters:
object- the managed instance to detach
-
evict
Description copied from interface:SessionRemove this instance from the session cache. Changes to the instance will not be synchronized with the database. This operation cascades to associated instances if the association is mapped with
CascadeType.DETACH.This operation is a synonym for
Session.detach(Object). -
load
Description copied from interface:SessionRead the persistent state associated with the given identifier into the given transient instance. -
merge
Description copied from interface:SessionCopy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped withCascadeType.MERGE.- Specified by:
mergein interfaceEntityManager- Specified by:
mergein interfaceSession- Parameters:
object- a detached instance with state to be copied- Returns:
- an updated persistent instance
-
merge
Description copied from interface:SessionCopy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped withCascadeType.MERGE. -
merge
Description copied from interface:SessionCopy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it is loaded using the givenEntityGraph, which is interpreted as a load graph. Return the persistent instance. If the given instance is unsaved, save a copy and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped withCascadeType.MERGE. -
persist
Description copied from interface:SessionMake a transient instance persistent and mark it for later insertion in the database. This operation cascades to associated instances if the association is mapped with
CascadeType.PERSIST.For entities with a generated id,
persist()ultimately results in generation of an identifier for the given instance. But this may happen asynchronously, when the session is flushed, depending on the identifier generation strategy.- Specified by:
persistin interfaceEntityManager- Specified by:
persistin interfaceSession- Parameters:
object- a transient instance to be made persistent
-
persist
Description copied from interface:SessionMake a transient instance persistent and mark it for later insertion in the database. This operation cascades to associated instances if the association is mapped with
CascadeType.PERSIST.For entities with a generated id,
persist()ultimately results in generation of an identifier for the given instance. But this may happen asynchronously, when the session is flushed, depending on the identifier generation strategy. -
lock
Description copied from interface:SessionObtain the specified lock level on the given managed instance associated with this session. This operation may be used to:
- perform a version check on an entity read from the second-level cache
by requesting
LockMode.READ, - schedule a version check at transaction commit by requesting
LockMode.OPTIMISTIC, - schedule a version increment at transaction commit by requesting
LockMode.OPTIMISTIC_FORCE_INCREMENT - upgrade to a pessimistic lock with
LockMode.PESSIMISTIC_READorLockMode.PESSIMISTIC_WRITE, or - immediately increment the version of the given instance by requesting
LockMode.PESSIMISTIC_FORCE_INCREMENT.
If the requested lock mode is already held on the given entity, this operation has no effect.
The modes
LockMode.WRITEandLockMode.UPGRADE_SKIPLOCKEDare not legal arguments tolock(). - perform a version check on an entity read from the second-level cache
by requesting
-
lock
public void lock(@Nonnull Object object, @Nonnull LockMode lockMode, @Nullable LockOption... lockOptions) Description copied from interface:SessionObtain the specified lock level on the given managed instance associated with this session, applying any other specified options. This operation may be used to:
- perform a version check on an entity read from the second-level cache
by requesting
LockMode.READ, - schedule a version check at transaction commit by requesting
LockMode.OPTIMISTIC, - schedule a version increment at transaction commit by requesting
LockMode.OPTIMISTIC_FORCE_INCREMENT - upgrade to a pessimistic lock with
LockMode.PESSIMISTIC_READorLockMode.PESSIMISTIC_WRITE, or - immediately increment the version of the given instance by requesting
LockMode.PESSIMISTIC_FORCE_INCREMENT.
If the requested lock mode is already held on the given entity, this operation has no effect.
The modes
LockMode.WRITEandLockMode.UPGRADE_SKIPLOCKEDare not legal arguments tolock(). - perform a version check on an entity read from the second-level cache
by requesting
-
lock
Description copied from interface:SessionObtain a lock on the given managed instance associated with this session, using the given lock options. -
refresh
Description copied from interface:SessionReread the state of the given managed instance associated with this session from the underlying database. This may be useful:
- when a database trigger alters the object state upon insert or update,
- after executing any HQL update or delete statement,
- after executing a native SQL statement, or
- after inserting a
BloborClob.
This operation cascades to associated instances if the association is mapped with
CascadeType.REFRESH.This operation requests
LockMode.READ. To obtain a stronger lock, callSession.refresh(Object,RefreshOption...), passing the appropriateLockModeas an option.- Specified by:
refreshin interfaceEntityManager- Specified by:
refreshin interfaceSession- Parameters:
object- a persistent instance associated with this session
-
refresh
-
remove
Description copied from interface:SessionMark a persistence instance associated with this session for removal from the underlying database. This operation cascades to associated instances if the association is mapped
CascadeType.REMOVE.Except when operating in fully JPA-compliant mode, this operation does, contrary to the JPA specification, accept a detached entity instance.
- Specified by:
removein interfaceEntityManager- Specified by:
removein interfaceSession- Parameters:
object- the managed persistent instance to remove, or a detached instance unless operating in fully JPA-compliant mode
-
getCurrentLockMode
Description copied from interface:SessionDetermine the current lock mode held on the given managed instance associated with this session.
Unlike the JPA-standard
EntityManager.getLockMode(Object), this operation may be called when no transaction is active, in which case it should returnLockMode.NONE, indicating that no pessimistic lock is held on the given entity.- Specified by:
getCurrentLockModein interfaceSession- Parameters:
object- a persistent instance associated with this session- Returns:
- the lock mode currently held on the given entity
-
clear
public void clear()Description copied from interface:SessionCompletely clear the persistence context. Evict all loaded instances, causing every managed entity currently associated with this session to transition to the detached state, and cancel all pending insertions, updates, and deletions.
Does not close open iterators or instances of
ScrollableResults.- Specified by:
clearin interfaceEntityManager- Specified by:
clearin interfaceSession
-
findMultiple
@Nonnull public <E> List<E> findMultiple(@Nonnull Class<E> entityType, @Nonnull List<?> ids, @Nullable FindOption... options) Description copied from interface:SessionReturn the persistent instances of the given entity class with the given identifiers as a list. The position of an instance in the returned list matches the position of its identifier in the given list of identifiers, and the returned list contains a null value if there is no persistent instance matching a given identifier. If an instance is already associated with the session, that instance is returned. This method never returns an uninitialized instance.
Every object returned by
findMultiple()is either an unproxied instance of the given entity class or a fully fetched proxy object.This method accepts
FindMultipleOption.BatchSizeas an option, allowing control over the number of records retrieved in a single database request. The performance impact of setting a batch size depends on whether a SQL array may be used to pass the list of identifiers to the database:- for databases which support standard SQL arrays, a smaller batch size might be extremely inefficient compared to a very large batch size or no batching at all, but
- on the other hand, for databases with no SQL array type, a large batch size results in long SQL statements with many JDBC parameters.
- Specified by:
findMultiplein interfaceEntityHandler- Specified by:
findMultiplein interfaceSession- Parameters:
entityType- the entity typeids- the list of identifiersoptions- options, if any- Returns:
- an ordered list of persistent instances, with null elements representing missing entities, whose positions in the list match the positions of their ids in the given list of identifiers
- See Also:
-
findMultiple
@Nonnull public <E> List<E> findMultiple(@Nonnull EntityGraph<E> entityGraph, @Nonnull List<?> ids, @Nullable FindOption... options) Description copied from interface:SessionReturn the persistent instances of the root entity of the given
EntityGraphwith the given identifiers as a list, fetching the associations specified by the graph, which is interpreted as a load graph. The position of an instance in the returned list matches the position of its identifier in the given list of identifiers, and the returned list contains a null value if there is no persistent instance matching a given identifier. If an instance is already associated with the session, that instance is returned. This method never returns an uninitialized instance.Every object returned by
findMultiple()is either an unproxied instance of the given entity class, or a fully-fetched proxy object.This method accepts
FindMultipleOption.BatchSizeas an option, allowing control over the number of records retrieved in a single database request. The performance impact of setting a batch size depends on whether a SQL array may be used to pass the list of identifiers to the database:- for databases which support standard SQL arrays a smaller batch size might be extremely inefficient compared to a very large batch size or no batching at all, but
- on the other hand, for databases with no SQL array type, a large batch size results in long SQL statements with many JDBC parameters.
- Specified by:
findMultiplein interfaceEntityHandler- Specified by:
findMultiplein interfaceSession- Parameters:
entityGraph- the entity graph interpreted as a load graphids- the list of identifiersoptions- options, if any- Returns:
- an ordered list of persistent instances, with null elements representing missing entities, whose positions in the list match the positions of their ids in the given list of identifiers
- See Also:
-
get
-
get
@Nonnull public <T> T get(@Nonnull Class<T> entityType, @Nonnull Object key, @Nullable FindOption... findOptions) - Specified by:
getin interfaceEntityHandler
-
get
@Nonnull public <T> T get(@Nonnull EntityGraph<T> entityGraph, @Nonnull Object key, @Nullable FindOption... findOptions) - Specified by:
getin interfaceEntityHandler
-
getMultiple
@Nonnull public <T> List<T> getMultiple(@Nonnull Class<T> entityType, @Nonnull List<?> keys, @Nullable FindOption... findOptions) - Specified by:
getMultiplein interfaceEntityHandler
-
getMultiple
@Nonnull public <T> List<T> getMultiple(@Nonnull EntityGraph<T> entityGraph, @Nonnull List<?> keys, @Nullable FindOption... findOptions) - Specified by:
getMultiplein interfaceEntityHandler
-
get
@Nonnull public <T> T get(@Nonnull Class<T> entityType, @Nonnull Object id, @Nonnull LockMode lockMode) Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
get
@Nonnull public Object get(@Nonnull String entityName, @Nonnull Object key, @Nullable FindOption... findOptions) Description copied from interface:SharedSessionContractForm ofSharedSessionContract.find(String,Object,FindOption...)throwingEntityNotFoundExceptionif no entity exists for that id rather than returning null.- Specified by:
getin interfaceSharedSessionContract- Parameters:
entityName- The entity namekey- The key (primary or natural, based onKeyType)findOptions- Options for the load operation.- Returns:
- a persistent instance
- See Also:
-
get
@Nonnull public Object get(@Nonnull String entityName, @Nonnull Object id, @Nonnull LockMode lockMode) Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
get
@Nonnull public <T> T get(@Nonnull Class<T> entityType, @Nonnull Object id, @Nonnull LockOptions lockOptions) Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
get
@Nonnull public Object get(@Nonnull String entityName, @Nonnull Object id, @Nonnull LockOptions lockOptions) Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists. -
getEntityName
Description copied from interface:SessionReturn the entity name for the given persistent entity.
If the given entity is an uninitialized proxy, the proxy is initialized by side effect.
- Specified by:
getEntityNamein interfaceSession- Parameters:
object- a persistent entity associated with this session- Returns:
- the entity name
-
getReference
Description copied from interface:SessionReturn a reference to the persistent instance with the given class and identifier, making the assumption that the instance is still persistent in the database. This method never results in access to the underlying data store, and thus might return a proxy that is initialized on-demand, when a non-identifier method is accessed.
Note that
Hibernate.createDetachedProxy(SessionFactory,Class,Object)may be used to obtain a detached reference.It's sometimes necessary to narrow a reference returned by
getReference()to a subtype of the given entity type. A direct Java typecast should never be used in this situation. Instead, the methodHibernate.unproxy(Object,Class)is the recommended way to narrow the type of a proxy object. Alternatively, a new reference may be obtained by simply callinggetReference()again, passing the subtype. Either way, the narrowed reference will usually not be identical to the original reference, when the references are compared using the==operator.- Specified by:
getReferencein interfaceEntityManager- Specified by:
getReferencein interfaceSession- Parameters:
entityType- the entity typeid- the identifier of a persistent instance that exists in the database- Returns:
- the persistent instance or proxy
-
getReference
Description copied from interface:SessionReturn a reference to the persistent instance of the given named entity with the given identifier, making the assumption that the instance is still persistent in the database. This method never results in access to the underlying data store, and thus might return a proxy that is initialized on-demand, when a non-identifier method is accessed.- Specified by:
getReferencein interfaceSession- Parameters:
entityName- the entity nameid- the identifier of a persistent instance that exists in the database- Returns:
- the persistent instance or proxy
-
getReference
Description copied from interface:SessionReturn a reference to the persistent instance with the same identity as the given instance, which might be detached, making the assumption that the instance is still persistent in the database. This method never results in access to the underlying data store, and thus might return a proxy that is initialized on-demand, when a non-identifier method is accessed.- Specified by:
getReferencein interfaceEntityManager- Specified by:
getReferencein interfaceSession- Parameters:
object- a detached persistent instance- Returns:
- the persistent instance or proxy
-
getReference
@Nonnull public <T> T getReference(@Nonnull Class<T> entityType, @Nonnull Object key, @Nonnull KeyType keyType) Description copied from interface:SessionReturn a reference to the persistent instance of the given entity type with the given key, which is interpreted according to the givenKeyType, making the assumption that the instance is still persistent in the database.- Specified by:
getReferencein interfaceSession- Parameters:
entityType- the entity typekey- the id or natural id of a persistent instance that exists in the databasekeyType- Whether the givenkeyshould be treated as an id or as a natural id
-
byId
Description copied from interface:SessionCreate anIdentifierLoadAccessinstance to retrieve an instance of the named entity type by its primary key.- Specified by:
byIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
IdentifierLoadAccessfor executing the lookup
-
byMultipleIds
Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the given entity type by their primary key values, using batching.- Specified by:
byMultipleIdsin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
MultiIdentifierLoadAccessfor executing the lookup - See Also:
-
byMultipleIds
Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the named entity type by their primary key values, using batching.- Specified by:
byMultipleIdsin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
MultiIdentifierLoadAccessfor executing the lookup
-
byId
Description copied from interface:SessionCreate anIdentifierLoadAccessinstance to retrieve an instance of the given entity type by its primary key.- Specified by:
byIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
IdentifierLoadAccessfor executing the lookup
-
byNaturalId
Deprecated.Description copied from interface:SessionCreate aNaturalIdLoadAccessinstance to retrieve an instance of the named entity type by its natural id, which may be a composite natural id. The entity must have at least one attribute annotatedNaturalId.- Specified by:
byNaturalIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
NaturalIdLoadAccessfor executing the lookup
-
byNaturalId
Deprecated.Description copied from interface:SessionCreate aNaturalIdLoadAccessinstance to retrieve an instance of the given entity type by its natural id, which may be a composite natural id. The entity must have at least one attribute annotatedNaturalId.- Specified by:
byNaturalIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
NaturalIdLoadAccessfor executing the lookup
-
bySimpleNaturalId
@Deprecated @Nonnull public <T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(@Nonnull String entityName) Deprecated.Description copied from interface:SessionCreate aSimpleNaturalIdLoadAccessinstance to retrieve an instance of the named entity type by its natural id, which must be a simple (non-composite) value. The entity must have exactly one attribute annotatedNaturalId.- Specified by:
bySimpleNaturalIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
SimpleNaturalIdLoadAccessfor executing the lookup
-
bySimpleNaturalId
@Deprecated @Nonnull public <T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(@Nonnull Class<T> entityClass) Deprecated.Description copied from interface:SessionCreate aSimpleNaturalIdLoadAccessinstance to retrieve an instance of the given entity type by its natural id, which must be a simple (non-composite) value. The entity must have exactly one attribute annotatedNaturalId.- Specified by:
bySimpleNaturalIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
SimpleNaturalIdLoadAccessfor executing the lookup
-
byMultipleNaturalId
@Deprecated @Nonnull public <T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(@Nonnull Class<T> entityClass) Deprecated.Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the given entity type by their by natural id values, using batching.- Specified by:
byMultipleNaturalIdin interfaceSession- Parameters:
entityClass- the entity type to be retrieved- Returns:
- an instance of
NaturalIdMultiLoadAccessfor executing the lookup
-
byMultipleNaturalId
@Deprecated @Nonnull public <T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(@Nonnull String entityName) Deprecated.Description copied from interface:SessionCreate aMultiIdentifierLoadAccessinstance to retrieve multiple instances of the named entity type by their by natural id values, using batching.- Specified by:
byMultipleNaturalIdin interfaceSession- Parameters:
entityName- the entity name of the entity type to be retrieved- Returns:
- an instance of
NaturalIdMultiLoadAccessfor executing the lookup
-
enableFilter
Description copied from interface:SharedSessionContractEnable 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.- Specified by:
enableFilterin interfaceSharedSessionContract- Parameters:
filterName- the name of the filter to be enabled.- Returns:
- the
Filterinstance representing the enabled filter. - See Also:
-
getEnabledFilter
Description copied from interface:SharedSessionContractRetrieve a currently enabled filter by name.- Specified by:
getEnabledFilterin interfaceSharedSessionContract- Parameters:
filterName- the name of the filter to be retrieved.- Returns:
- the
Filterinstance representing the enabled filter.
-
disableFilter
Description copied from interface:SharedSessionContractDisable the named filter for the current session.- Specified by:
disableFilterin interfaceSharedSessionContract- Parameters:
filterName- the name of the filter to be disabled.
-
getStatistics
Description copied from interface:SessionGet the statistics for this session.- Specified by:
getStatisticsin interfaceSession- Returns:
- the session statistics being collected for this session
-
isReadOnly
Description copied from interface:SessionIs the specified entity or proxy read-only?
To get the default read-only/modifiable setting used for entities and proxies that are loaded into the session use
Session.isDefaultReadOnly()- Specified by:
isReadOnlyin interfaceSession- Parameters:
entityOrProxy- an entity or proxy- Returns:
trueif the entity or proxy is read-only,falseif the entity or proxy is modifiable.- See Also:
-
setReadOnly
Description copied from interface:SessionSet an unmodified persistent object to read-only mode, or a read-only object to modifiable mode. In read-only mode, no snapshot is maintained, the instance is never dirty-checked, and mutations to the fields of the entity are not made persistent.
If the entity or proxy already has the specified read-only/modifiable setting, then this method does nothing.
To set the default read-only/modifiable setting used for all entities and proxies that are loaded into the session use
Session.setDefaultReadOnly(boolean).To override the default read-only mode of the current session for all entities and proxies returned by a given
Query, useSelectionQuery.setReadOnly(boolean).Every instance of an immutable entity is loaded in read-only mode. An immutable entity may not be set to modifiable.
- Specified by:
setReadOnlyin interfaceSession- Parameters:
entityOrProxy- an entity or proxyreadOnly-trueif the entity or proxy should be made read-only;falseif the entity or proxy should be made modifiable- See Also:
-
isFetchProfileEnabled
Description copied from interface:SessionIs the fetch profile with the given name enabled in this session?- Specified by:
isFetchProfileEnabledin interfaceSession- Parameters:
name- the name of the profile- Returns:
- True if fetch profile is enabled; false if not.
- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
enableFetchProfile
Description copied from interface:SessionEnable the fetch profile with the given name in this session. If the requested fetch profile is already enabled, the call has no effect.- Specified by:
enableFetchProfilein interfaceSession- Parameters:
name- the name of the fetch profile to be enabled- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
disableFetchProfile
Description copied from interface:SessionDisable the fetch profile with the given name in this session. If the requested fetch profile is not currently enabled, the call has no effect.- Specified by:
disableFetchProfilein interfaceSession- Parameters:
name- the name of the fetch profile to be disabled- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
getLobHelper
-
getManagedEntities
Description copied from interface:SessionObtain the collection of all managed entities which belong to this persistence context.- Specified by:
getManagedEntitiesin interfaceSession
-
getManagedEntities
Description copied from interface:SessionObtain a collection of all managed instances of the entity type with the given entity name which belong to this persistence context.- Specified by:
getManagedEntitiesin interfaceSession
-
getManagedEntities
Description copied from interface:SessionObtain a collection of all managed entities of the given type which belong to this persistence context. This operation is not polymorphic, and does not return instances of subtypes of the given entity type.- Specified by:
getManagedEntitiesin interfaceSession
-
getManagedEntities
Description copied from interface:SessionObtain a collection of all managed entities of the given type which belong to this persistence context. This operation is not polymorphic, and does not return instances of subtypes of the given entity type.- Specified by:
getManagedEntitiesin interfaceSession
-
sessionWithOptions
Description copied from interface:SharedSessionContractObtain aSessionbuilder with the ability to copy certain information from this session.- Specified by:
sessionWithOptionsin interfaceSharedSessionContract- Returns:
- the session builder
-
addEventListeners
Description copied from interface:SessionAdd one or more listeners to the Session- Specified by:
addEventListenersin interfaceSession- Parameters:
listeners- the listener(s) to add
-
createEntityGraph
Description copied from interface:SessionCreate 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 interfaceSession- Specified by:
createEntityGraphin interfaceSharedSessionContract- Parameters:
rootType- The root entity of the graph- See Also:
-
createEntityGraph
Deprecated.Description copied from interface:SessionCreate 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 interfaceEntityManager- Specified by:
createEntityGraphin interfaceSession- Specified by:
createEntityGraphin interfaceSharedSessionContract- Parameters:
graphName- The name of the predefined named entity graph
-
createEntityGraph
@Deprecated @Nullable public <T> RootGraph<T> createEntityGraph(@Nonnull Class<T> rootType, @Nonnull String graphName) Deprecated.Description copied from interface:SessionCreate a new mutable instance ofEntityGraph, based on a predefined named entity graph whose root type is exactly the given entity type, allowing customization of the graph, or returnnullif there is no predefined graph with the given name.- Specified by:
createEntityGraphin interfaceSession- Specified by:
createEntityGraphin interfaceSharedSessionContract- Parameters:
rootType- the root entity class of the graphgraphName- The name of the predefined named entity graph
-
getEntityGraph
Description copied from interface:SessionObtain a mutable copy of a predefined named entity graph.- Specified by:
getEntityGraphin interfaceEntityHandler- Specified by:
getEntityGraphin interfaceSession- Specified by:
getEntityGraphin interfaceSharedSessionContract- Parameters:
graphName- The name of the predefined named entity graph- See Also:
-
getEntityGraph
@Nonnull public <T> RootGraph<T> getEntityGraph(@Nonnull Class<T> entityClass, @Nonnull String name) Description copied from interface:SessionObtain a mutable copy of a predefined named entity graph whose root type is exactly the given entity type.- Specified by:
getEntityGraphin interfaceEntityHandler- Specified by:
getEntityGraphin interfaceSession- Specified by:
getEntityGraphin interfaceSharedSessionContract- Parameters:
entityClass- the root entity class of the graphname- The name of the predefined named entity graph- See Also:
-
getEntityGraphs
Description copied from interface:SessionRetrieve all namedEntityGraphs with the given root entity type.- Specified by:
getEntityGraphsin interfaceEntityHandler- Specified by:
getEntityGraphsin interfaceSession- Specified by:
getEntityGraphsin interfaceSharedSessionContract- See Also:
-
runWithConnection
- Specified by:
runWithConnectionin interfaceEntityHandler
-
callWithConnection
- Specified by:
callWithConnectionin interfaceEntityHandler
-
createQuery
@Nonnull public <R> SelectionQuery<R> createQuery(@Nonnull String queryString, @Nonnull Class<R> resultClass) Description copied from interface:SessionCreate 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 interfaceSession- 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 public <T> SelectionQuery<T> createQuery(@Nonnull String query, @Nonnull EntityGraph<T> entityGraph) - Specified by:
createQueryin interfaceEntityHandler- Specified by:
createQueryin interfaceSharedSessionContract- See Also:
-
createQuery
@Nonnull public <R> SelectionQuery<R> createQuery(@Nonnull TypedQueryReference<R> typedQueryReference) Description copied from interface:SessionCreate a typedQueryinstance for the given typed query reference.- Specified by:
createQueryin interfaceEntityHandler- Specified by:
createQueryin interfaceSession- Specified by:
createQueryin interfaceSharedSessionContract- Parameters:
typedQueryReference- the type query reference- Returns:
- The
Queryinstance for execution - See Also:
-
createQuery
Description copied from interface:SessionCreate 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- Specified by:
createQueryin interfaceSession- Specified by:
createQueryin interfaceSharedSessionContract
-
createNamedQuery
@Nonnull public <R> SelectionQuery<R> createNamedQuery(@Nonnull String name, @Nonnull Class<R> resultClass) Description copied from interface:SessionCreate 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 interfaceSession- 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:
-
createNamedStatement
- Specified by:
createNamedStatementin interfaceEntityHandler- Specified by:
createNamedStatementin interfaceSharedSessionContract
-
createNamedQuery
@Nonnull public <R> NativeQuery<R> createNamedQuery(@Nonnull String name, @Nonnull String resultSetMappingName) - Specified by:
createNamedQueryin interfaceSharedSessionContract
-
createNamedQuery
@Nonnull public <R> NativeQuery<R> createNamedQuery(@Nonnull String name, @Nonnull String resultSetMappingName, @Nonnull Class<R> resultClass) - Specified by:
createNamedQueryin interfaceSharedSessionContract
-
createNativeStatement
- Specified by:
createNativeStatementin interfaceEntityHandler- Specified by:
createNativeStatementin interfaceSharedSessionContract
-
createNamedQuery
Description copied from interface:SessionCreate 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- Specified by:
createNamedQueryin interfaceSession- Specified by:
createNamedQueryin interfaceSharedSessionContract
-
createSelectionQuery
Description copied from interface:SharedSessionContractCreate aSelectionQueryreference for the givenCriteriaQuery.- Specified by:
createSelectionQueryin interfaceSharedSessionContract- See Also:
-
createQuery
Description copied from interface:SharedSessionContract- Specified by:
createQueryin interfaceEntityHandler- Specified by:
createQueryin interfaceSharedSessionContract- See Also:
-
statelessWithOptions
Description copied from interface:SharedSessionContractObtain aStatelessSessionbuilder with the ability to copy certain information from this session.- Specified by:
statelessWithOptionsin interfaceSharedSessionContract- Returns:
- the session builder
-
getTenantIdentifier
Description copied from interface:SharedSessionContractObtain the tenant identifier associated with this session, as a string.- Specified by:
getTenantIdentifierin interfaceSharedSessionContract- Returns:
- The tenant identifier associated with this session, or
null - See Also:
-
getTenantIdentifierValue
Description copied from interface:SharedSessionContractObtain the tenant identifier associated with this session.- Specified by:
getTenantIdentifierValuein interfaceSharedSessionContract- Returns:
- The tenant identifier associated with this session, or
null - See Also:
-
close
Description copied from interface:SharedSessionContractEnd the session by releasing the JDBC connection and cleaning up.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceEntityHandler- Specified by:
closein interfaceSharedSessionContract- Throws:
HibernateException- Indicates problems cleaning up.
-
isOpen
public boolean isOpen()Description copied from interface:SharedSessionContractCheck if the session is still open.- Specified by:
isOpenin interfaceEntityHandler- Specified by:
isOpenin interfaceSharedSessionContract- Returns:
trueif it is open
-
isConnected
public boolean isConnected()Description copied from interface:SharedSessionContractCheck if the session is currently connected.- Specified by:
isConnectedin interfaceSharedSessionContract- Returns:
trueif it is connected
-
beginTransaction
Description copied from interface:SharedSessionContractBegin 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.- Specified by:
beginTransactionin interfaceSharedSessionContract- Returns:
- an instance of
Transactionrepresenting the new transaction - See Also:
-
getTransaction
Description copied from interface:SharedSessionContractGet theTransactioninstance associated with this session.- Specified by:
getTransactionin interfaceEntityHandler- Specified by:
getTransactionin interfaceSharedSessionContract- Returns:
- an instance of
Transactionrepresenting the transaction associated with this session - See Also:
-
getNamedProcedureCall
Description copied from interface:SharedSessionContractObtain aProcedureCallbased on a named template- Specified by:
getNamedProcedureCallin interfaceSharedSessionContract- Parameters:
name- The name given to the template- Returns:
- The ProcedureCall
- See Also:
-
createStoredProcedureCall
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure.- Specified by:
createStoredProcedureCallin interfaceSharedSessionContract- Parameters:
procedureName- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureCall
@Nonnull public ProcedureCall createStoredProcedureCall(@Nonnull String procedureName, @Nonnull Class<?>... resultClasses) Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings. Each given class is considered a "root return".- Specified by:
createStoredProcedureCallin interfaceSharedSessionContract- 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 public ProcedureCall createStoredProcedureCall(@Nonnull String procedureName, @Nonnull String... resultSetMappings) Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings.- Specified by:
createStoredProcedureCallin interfaceSharedSessionContract- 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
Description copied from interface:SharedSessionContractObtain aProcedureCallbased on a named template- Specified by:
createNamedStoredProcedureQueryin interfaceEntityHandler- Specified by:
createNamedStoredProcedureQueryin interfaceSharedSessionContract- Parameters:
name- The name given to the template- Returns:
- The ProcedureCall
- See Also:
-
createStoredProcedureQuery
Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure.- Specified by:
createStoredProcedureQueryin interfaceEntityHandler- Specified by:
createStoredProcedureQueryin interfaceSharedSessionContract- Parameters:
procedureName- The name of the procedure.- Returns:
- The representation of the procedure call.
-
createStoredProcedureQuery
@Nonnull public ProcedureCall createStoredProcedureQuery(@Nonnull String procedureName, @Nonnull Class... resultClasses) Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings. Each given class is considered a "root return".- Specified by:
createStoredProcedureQueryin interfaceEntityHandler- Specified by:
createStoredProcedureQueryin interfaceSharedSessionContract- 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 public ProcedureCall createStoredProcedureQuery(@Nonnull String procedureName, @Nonnull String... resultSetMappings) Description copied from interface:SharedSessionContractCreate aProcedureCallto a stored procedure with the given result set entity mappings.- Specified by:
createStoredProcedureQueryin interfaceEntityHandler- Specified by:
createStoredProcedureQueryin interfaceSharedSessionContract- 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
Description copied from interface:SharedSessionContractGet the session-level JDBC batch size for the current session.- Specified by:
getJdbcBatchSizein interfaceSharedSessionContract- Returns:
- the current session-level JDBC batch size
- See Also:
-
setJdbcBatchSize
Description copied from interface:SharedSessionContractSet the session-level JDBC batch size. Override the factory-level JDBC batch size controlled by the configuration property "hibernate.jdbc.batch_size".- Specified by:
setJdbcBatchSizein interfaceSharedSessionContract- Parameters:
jdbcBatchSize- the new session-level JDBC batch size- See Also:
-
getFetchBatchSize
public int getFetchBatchSize()Description copied from interface:SessionGet the maximum batch size for batch fetching associations by id in this session.- Specified by:
getFetchBatchSizein interfaceSession
-
setFetchBatchSize
public void setFetchBatchSize(int batchSize) Description copied from interface:SessionSet the maximum batch size for batch fetching associations by id in this session. Override the factory-level default controlled by the configuration property "hibernate.default_batch_fetch_size".
- If
batchSize>1, then batch fetching is enabled. - If
batchSize<0, the batch size is inherited from the factory-level setting. - Otherwise, batch fetching is disabled.
- Specified by:
setFetchBatchSizein interfaceSession- Parameters:
batchSize- the maximum batch size for batch fetching- See Also:
- If
-
isSubselectFetchingEnabled
public boolean isSubselectFetchingEnabled()Description copied from interface:SessionDetermine if subselect fetching is enabled in this session.- Specified by:
isSubselectFetchingEnabledin interfaceSession- Returns:
trueis subselect fetching is enabled
-
setSubselectFetchingEnabled
public void setSubselectFetchingEnabled(boolean enabled) Description copied from interface:SessionEnable or disable subselect fetching in this session. Override the factory-level default controlled by the configuration property "hibernate.use_subselect_fetch".- Specified by:
setSubselectFetchingEnabledin interfaceSession- Parameters:
enabled-trueto enable subselect fetching- See Also:
-
getCriteriaBuilder
Description copied from interface:SharedSessionContract- Specified by:
getCriteriaBuilderin interfaceEntityHandler- Specified by:
getCriteriaBuilderin interfaceSharedSessionContract- Returns:
- an instance of
HibernateCriteriaBuilder - See Also:
-
doWork
Description copied from interface:SharedSessionContractPerform work using theConnectionunderlying by this session.- Specified by:
doWorkin interfaceSharedSessionContract- Parameters:
work- The work to be performed.- Throws:
HibernateException- Generally indicates wrappedSQLException
-
doReturningWork
Description copied from interface:SharedSessionContractPerform work using theConnectionunderlying by this session, and return a result.- Specified by:
doReturningWorkin interfaceSharedSessionContract- 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
-
createNativeQuery
Deprecated.Description copied from interface:SharedSessionContractCreate aNativeQueryinstance for the given native SQL query.- Specified by:
createNativeQueryin interfaceEntityHandler- Specified by:
createNativeQueryin interfaceSharedSessionContract- Parameters:
sqlString- The native (SQL) query string- Returns:
- The
NativeQueryinstance for manipulation and execution - See Also:
-
createNativeQuery
@Nonnull public NativeQuery createNativeQuery(@Nonnull String sqlString, @Nonnull Class 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
public <R> NativeQuery<R> createNativeQuery(String sqlString, Class<R> resultClass, 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
@Deprecated @Nonnull public NativeQuery createNativeQuery(@Nonnull String sqlString, @Nonnull String resultSetMappingName) Deprecated.- Specified by:
createNativeQueryin interfaceEntityHandler- Specified by:
createNativeQueryin interfaceSharedSessionContract
-
createNativeQuery
@Nonnull public <T> TypedQuery<T> createNativeQuery(@Nonnull String sql, @Nonnull jakarta.persistence.sql.ResultSetMapping<T> resultSetMapping) - Specified by:
createNativeQueryin interfaceEntityHandler- Specified by:
createNativeQueryin interfaceSharedSessionContract
-
createNativeQuery
public <R> NativeQuery<R> createNativeQuery(String sqlString, String resultSetMappingName, 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:
-
createSelectionQuery
Description copied from interface:SharedSessionContractCreate 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().- Specified by:
createSelectionQueryin interfaceSharedSessionContract- Parameters:
hqlString- The HQLselectquery as a stringresultType- TheClassobject representing the query result type, which should not beObject.class- See Also:
- If the query has a single item in the
-
createSelectionQuery
Description copied from interface:SharedSessionContractCreate 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().- Specified by:
createSelectionQueryin interfaceSharedSessionContract- Parameters:
hqlString- The HQLselectquery as a stringresultGraph- AnEntityGraphwhose root type is the query result type, which is interpreted as a load graph- See Also:
- If the query has an explicit
-
createSelectionQuery
Description copied from interface:SharedSessionContractCreate aSelectionQueryreference for the givenCriteriaQuery.- Specified by:
createSelectionQueryin interfaceSharedSessionContract- See Also:
-
createMutationQuery
Description copied from interface:SharedSessionContractCreate aMutationQueryreference for the given HQL insert, update, or delete statement.- Specified by:
createMutationQueryin interfaceSharedSessionContract- Parameters:
hqlString- The HQLinsert,update, ordeletestatement
-
createStatement
- Specified by:
createStatementin interfaceEntityHandler- Specified by:
createStatementin interfaceSharedSessionContract
-
createStatement
- Specified by:
createStatementin interfaceEntityHandler- Specified by:
createStatementin 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 update criteria tree- Specified by:
createMutationQueryin interfaceSharedSessionContract
-
createQuery
Description copied from interface:Session- Specified by:
createQueryin interfaceEntityManager- Specified by:
createQueryin interfaceSession
-
createMutationQuery
Description copied from interface:SharedSessionContractCreate aMutationQueryfrom the given insert criteria tree- Specified by:
createMutationQueryin interfaceSharedSessionContract
-
createNativeMutationQuery
Description copied from interface:SharedSessionContractCreate aNativeQueryinstance for the given native SQL statement.- Specified by:
createNativeMutationQueryin interfaceSharedSessionContract- Parameters:
sqlString- a native SQL statement string- Returns:
- The NativeQuery instance for manipulation and execution
-
createNamedSelectionQuery
@Nonnull public <R> SelectionQuery<R> createNamedSelectionQuery(@Nonnull String name, @Nonnull Class<R> resultType) Description copied from interface:SharedSessionContractCreate aSelectionQueryinstance for the namedNamedQuerywith the given result type.- Specified by:
createNamedSelectionQueryin interfaceSharedSessionContract
-
createNamedMutationQuery
Description copied from interface:SharedSessionContractCreate aMutationQueryinstance for the given named insert, update, or delete HQL query. The named query might be defined as HQL) or native-SQL.- Specified by:
createNamedMutationQueryin interfaceSharedSessionContract
-
find
Description copied from interface:SessionReturn the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance.
The object returned by
get()orfind()is either an unproxied instance of the given entity class, or a fully-fetched proxy object.This operation requests
LockMode.NONE, that is, no lock, allowing the object to be retrieved from the cache without the cost of database access. However, if it is necessary to read the state from the database, the object will be returned with the lock modeLockMode.READ.To bypass the second-level cache, and ensure that the state of the requested instance is read directly from the database, either:
- call
Session.find(Class,Object,FindOption...), passingCacheRetrieveMode.BYPASSas an option, - call
Session.find(Class,Object,FindOption...)with the explicit lock modeLockMode.READ, or - set the cache mode to
CacheRetrieveMode.BYPASSbefore calling this method.
- Specified by:
findin interfaceEntityHandler- Specified by:
findin interfaceSession- Parameters:
entityClass- the entity typeprimaryKey- an identifier- Returns:
- a fully-fetched persistent instance or null
- call
-
find
-
find
-
find
@Nullable public <T> T find(@Nonnull Class<T> entityClass, @Nonnull Object primaryKey, @Nullable FindOption... options) Description copied from interface:SessionThe option
KeyType.NATURALspecifies that the given id should be interpreted as a natural id.- Specified by:
findin interfaceEntityHandler- Specified by:
findin interfaceSession- Parameters:
entityClass- the entity typeprimaryKey- an identifieroptions- options controlling the behavior of the operation
-
find
@Nullable public <T> T find(@Nonnull EntityGraph<T> entityGraph, @Nonnull Object primaryKey, @Nullable FindOption... options) - Specified by:
findin interfaceEntityHandler
-
find
@Nullable public Object find(@Nonnull String entityName, @Nonnull Object primaryKey, @Nullable FindOption... options) Description copied from interface:SharedSessionContractCorollary toEntityHandler.find(Class,Object,FindOption...)for dynamic models.- Specified by:
findin interfaceSharedSessionContract- Parameters:
entityName- The entity nameprimaryKey- The key (primary or natural, based onKeyType)options- Options for the load operation.- Returns:
- The persistent instance, or null
- See Also:
-
lock
- Specified by:
lockin interfaceEntityManager
-
lock
public void lock(@Nonnull Object entity, @Nonnull LockModeType lockMode, @Nullable Map<String, Object> properties) - Specified by:
lockin interfaceEntityManager
-
lock
public void lock(@Nonnull Object entity, @Nonnull LockModeType lockMode, @Nullable LockOption... options) - Specified by:
lockin interfaceEntityManager
-
refresh
-
refresh
public void refresh(@Nonnull Object entity, @Nonnull LockModeType lockMode, @Nullable Map<String, Object> properties) - Specified by:
refreshin interfaceEntityManager
-
refresh
Description copied from interface:Session- Specified by:
refreshin interfaceEntityManager- Specified by:
refreshin interfaceSession- Parameters:
entity- a persistent instance associated with this sessionoptions- options controlling the behavior of the operation
-
contains
- Specified by:
containsin interfaceEntityManager
-
getLockMode
- Specified by:
getLockModein interfaceEntityManager
-
setProperty
Description copied from interface:SessionSet a hint. The hints understood by Hibernate are enumerated byAvailableHints.- Specified by:
setPropertyin interfaceEntityHandler- Specified by:
setPropertyin interfaceSession- See Also:
-
getProperties
- Specified by:
getPropertiesin interfaceEntityHandler
-
joinTransaction
public void joinTransaction()Description copied from interface:SharedSessionContractJoin the currently active JTA transaction.- Specified by:
joinTransactionin interfaceEntityManager- Specified by:
joinTransactionin interfaceSharedSessionContract- See Also:
-
isJoinedToTransaction
public boolean isJoinedToTransaction()Description copied from interface:SharedSessionContractCheck if the session is joined to the current transaction.- Specified by:
isJoinedToTransactionin interfaceEntityManager- Specified by:
isJoinedToTransactionin interfaceSharedSessionContract- See Also:
-
unwrap
- Specified by:
unwrapin interfaceEntityHandler
-
getNamedNativeQuery
Deprecated.- Specified by:
getNamedNativeQueryin interfaceSession
-
getDelegate
Deprecated.- Specified by:
getDelegatein interfaceEntityManager
-
getEntityManagerFactory
- Specified by:
getEntityManagerFactoryin interfaceEntityHandler
-
getMetamodel
- Specified by:
getMetamodelin interfaceEntityHandler
-