Class StageSessionImpl

  • All Implemented Interfaces:
    Stage.Closeable, Stage.Session

    public class StageSessionImpl
    extends java.lang.Object
    implements Stage.Session
    Implements the Stage.Session API. This delegating class is needed to avoid name clashes when implementing both Session and Session.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Stage.Session clear()
      Completely clear the session.
      java.util.concurrent.CompletionStage<java.lang.Void> close()  
      boolean contains​(java.lang.Object entity)
      Determine if the given instance belongs to this persistence context.
      <T> jakarta.persistence.EntityGraph<T> createEntityGraph​(java.lang.Class<T> rootType)
      Create a new mutable EntityGraph
      <T> jakarta.persistence.EntityGraph<T> createEntityGraph​(java.lang.Class<T> rootType, java.lang.String graphName)
      Create a new mutable copy of a named EntityGraph
      Stage.MutationQuery createMutationQuery​(java.lang.String queryString)
      Create an instance of Stage.MutationQuery for the given HQL/JPQL update or delete statement.
      <R> Stage.Query<R> createNamedQuery​(java.lang.String queryName)
      Create an instance of Stage.Query for the named query.
      <R> Stage.SelectionQuery<R> createNamedQuery​(java.lang.String queryName, java.lang.Class<R> resultType)
      Create an instance of Stage.SelectionQuery for the named query.
      <R> Stage.Query<R> createNativeQuery​(java.lang.String queryString)
      Create an instance of Stage.Query for the given SQL query string, or SQL update, insert, or delete statement.
      <R> Stage.SelectionQuery<R> createNativeQuery​(java.lang.String queryString, java.lang.Class<R> resultType)
      Create an instance of Stage.Query for the given SQL query string, using the given resultType to interpret the results.
      <R> Stage.SelectionQuery<R> createNativeQuery​(java.lang.String queryString, java.lang.Class<R> resultType, AffectedEntities affectedEntities)
      Create an instance of Stage.SelectionQuery for the given SQL query string, using the given resultType to interpret the results.
      <R> Stage.Query<R> createNativeQuery​(java.lang.String queryString, AffectedEntities affectedEntities)
      Create an instance of Stage.Query for the given SQL query string, or SQL update, insert, or delete statement.
      <R> Stage.SelectionQuery<R> createNativeQuery​(java.lang.String queryString, ResultSetMapping<R> resultSetMapping)
      Create an instance of Stage.SelectionQuery for the given SQL query string, using the given ResultSetMapping to interpret the result set.
      <R> Stage.SelectionQuery<R> createNativeQuery​(java.lang.String queryString, ResultSetMapping<R> resultSetMapping, AffectedEntities affectedEntities)
      Create an instance of Stage.SelectionQuery for the given SQL query string, using the given ResultSetMapping to interpret the result set.
      <R> Stage.MutationQuery createQuery​(jakarta.persistence.criteria.CriteriaDelete<R> criteriaDelete)
      Create an instance of Stage.MutationQuery for the given criteria delete.
      <R> Stage.SelectionQuery<R> createQuery​(jakarta.persistence.criteria.CriteriaQuery<R> criteriaQuery)
      Create an instance of Stage.SelectionQuery for the given criteria query.
      <R> Stage.MutationQuery createQuery​(jakarta.persistence.criteria.CriteriaUpdate<R> criteriaUpdate)
      Create an instance of Stage.MutationQuery for the given criteria update.
      <R> Stage.Query<R> createQuery​(java.lang.String queryString)
      Create an instance of Stage.Query for the given HQL/JPQL query string or HQL/JPQL update or delete statement.
      <R> Stage.SelectionQuery<R> createQuery​(java.lang.String queryString, java.lang.Class<R> resultType)
      Create an instance of Stage.SelectionQuery for the given HQL/JPQL query string and query result type.
      <R> Stage.SelectionQuery<R> createSelectionQuery​(java.lang.String queryString)
      Create an instance of Stage.SelectionQuery for the given HQL/JPQL query string.
      Stage.Transaction currentTransaction()
      Obtain the transaction currently associated with this session, if any.
      Stage.Session detach​(java.lang.Object entity)
      Remove this instance from the session cache.
      Stage.Session disableFetchProfile​(java.lang.String name)
      Disable a particular fetch profile on this session, or do nothing if the requested fetch profile is not enabled.
      void disableFilter​(java.lang.String filterName)
      Disable the named filter for this session.
      Stage.Session enableFetchProfile​(java.lang.String name)
      Enable a particular fetch profile on this session, or do nothing if requested fetch profile is already enabled.
      org.hibernate.Filter enableFilter​(java.lang.String filterName)
      Enable the named filter for this session.
      <E,​T>
      java.util.concurrent.CompletionStage<T>
      fetch​(E entity, jakarta.persistence.metamodel.Attribute<E,​T> field)
      Fetch a lazy property of the given entity, identified by a JPA attribute metamodel.
      <T> java.util.concurrent.CompletionStage<T> fetch​(T association)
      Asynchronously fetch an association that's configured for lazy loading.
      <T> java.util.concurrent.CompletionStage<T> find​(jakarta.persistence.EntityGraph<T> entityGraph, java.lang.Object id)
      Asynchronously return the persistent instance with the given identifier of an entity class, using the given EntityGraph as a fetch plan.
      <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
      Asynchronously return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.
      <T> java.util.concurrent.CompletionStage<java.util.List<T>> find​(java.lang.Class<T> entityClass, java.lang.Object... ids)
      Asynchronously return the persistent instances of the given entity class with the given identifiers, or null if there is no such persistent instance.
      <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass, java.lang.Object id, jakarta.persistence.LockModeType lockModeType)
      Asynchronously return the persistent instance of the given entity class with the given identifier, requesting the given LockModeType.
      <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass, java.lang.Object primaryKey, org.hibernate.LockMode lockMode)
      Asynchronously return the persistent instance of the given entity class with the given identifier, requesting the given LockMode.
      <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass, java.lang.Object primaryKey, org.hibernate.LockOptions lockOptions)  
      <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass, Identifier<T> id)
      Asynchronously return the persistent instance of the given entity class with the given natural identifiers, or null if there is no such persistent instance.
      java.util.concurrent.CompletionStage<java.lang.Void> flush()
      Force this session to flush asynchronously.
      java.lang.Integer getBatchSize()
      The session-level batch size, or null if it has not been overridden.
      org.hibernate.CacheMode getCacheMode()
      Get the current cache mode.
      org.hibernate.Filter getEnabledFilter​(java.lang.String filterName)
      Retrieve a currently enabled filter by name.
      <T> jakarta.persistence.EntityGraph<T> getEntityGraph​(java.lang.Class<T> rootType, java.lang.String graphName)
      Obtain a named EntityGraph
      org.hibernate.FlushMode getFlushMode()
      Get the current flush mode for this session.
      org.hibernate.LockMode getLockMode​(java.lang.Object entity)
      Determine the current lock mode of the given entity.
      ReactiveConnection getReactiveConnection()  
      <T> T getReference​(java.lang.Class<T> entityClass, java.lang.Object id)
      Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.
      <T> T getReference​(T entity)
      Return the persistent instance with the same identity as the given instance, which might be detached, assuming that the instance is still persistent in the database.
      <T> ResultSetMapping<T> getResultSetMapping​(java.lang.Class<T> resultType, java.lang.String mappingName)
      Obtain a native SQL result set mapping defined via the annotation SqlResultSetMapping.
      boolean isDefaultReadOnly()  
      boolean isFetchProfileEnabled​(java.lang.String name)
      Determine if the fetch profile with the given name is enabled for this session.
      boolean isOpen()  
      boolean isReadOnly​(java.lang.Object entityOrProxy)
      Is the specified entity or proxy read-only?
      java.util.concurrent.CompletionStage<java.lang.Void> lock​(java.lang.Object entity, jakarta.persistence.LockModeType lockModeType)
      Obtain the specified lock level upon the given object.
      java.util.concurrent.CompletionStage<java.lang.Void> lock​(java.lang.Object entity, org.hibernate.LockMode lockMode)
      Obtain the specified lock level upon the given object.
      java.util.concurrent.CompletionStage<java.lang.Void> lock​(java.lang.Object entity, org.hibernate.LockOptions lockOptions)  
      <T> java.util.concurrent.CompletionStage<T> merge​(T entity)
      Copy the state of the given object onto the persistent instance with the same identifier.
      <T> java.util.concurrent.CompletionStage<java.lang.Void> merge​(T... entity)
      Merge multiple entity instances at once.
      java.util.concurrent.CompletionStage<java.lang.Void> persist​(java.lang.Object entity)
      Asynchronously persist the given transient instance, first assigning a generated identifier.
      java.util.concurrent.CompletionStage<java.lang.Void> persist​(java.lang.Object... entity)
      Persist multiple transient entity instances at once.
      java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity)
      Re-read the state of the given instance from the underlying database.
      java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object... entity)
      Refresh multiple entity instances at once.
      java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity, jakarta.persistence.LockModeType lockModeType)
      Re-read the state of the given instance from the underlying database, requesting the given LockModeType.
      java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity, org.hibernate.LockMode lockMode)
      Re-read the state of the given instance from the underlying database, requesting the given LockMode.
      java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity, org.hibernate.LockOptions lockOptions)  
      java.util.concurrent.CompletionStage<java.lang.Void> remove​(java.lang.Object entity)
      Asynchronously remove a persistent instance from the datastore.
      java.util.concurrent.CompletionStage<java.lang.Void> remove​(java.lang.Object... entity)
      Remove multiple entity instances at once.
      Stage.Session setBatchSize​(java.lang.Integer batchSize)
      Set the session-level batch size, overriding the batch size set by the configuration property hibernate.jdbc.batch_size.
      Stage.Session setCacheMode​(org.hibernate.CacheMode cacheMode)
      Set the cache mode for this session.
      Stage.Session setCacheRetrieveMode​(jakarta.persistence.CacheRetrieveMode cacheRetrieveMode)
      Set the CacheRetrieveMode for this session.
      Stage.Session setCacheStoreMode​(jakarta.persistence.CacheStoreMode cacheStoreMode)
      Set the CacheStoreMode for this session.
      Stage.Session setDefaultReadOnly​(boolean readOnly)
      Change the default for entities and proxies loaded into this session from modifiable to read-only mode, or from modifiable to read-only mode.
      Stage.Session setFlushMode​(jakarta.persistence.FlushModeType flushModeType)
      Set the flush mode for this session.
      Stage.Session setFlushMode​(org.hibernate.FlushMode flushMode)
      Set the flush mode for this session.
      Stage.Session setReadOnly​(java.lang.Object entityOrProxy, boolean readOnly)
      Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.
      <T> java.util.concurrent.CompletionStage<T> unproxy​(T association)
      Asynchronously fetch an association that's configured for lazy loading, and unwrap the underlying entity implementation from any proxy.
      <T> T unwrap​(java.lang.Class<T> clazz)  
      <T> java.util.concurrent.CompletionStage<T> withTransaction​(java.util.function.Function<Stage.Transaction,​java.util.concurrent.CompletionStage<T>> work)
      Performs the given work within the scope of a database transaction, automatically flushing the session.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • flush

        public java.util.concurrent.CompletionStage<java.lang.Void> flush()
        Description copied from interface: Stage.Session
        Force this session to flush asynchronously. Must be called at the end of a unit of work, before committing the transaction and closing the session. Flushing is the process of synchronizing the underlying persistent store with state held in memory.
         session.flush().thenAccept(v -> print("done saving changes"));
         
        Specified by:
        flush in interface Stage.Session
        See Also:
        EntityManager.flush()
      • fetch

        public <T> java.util.concurrent.CompletionStage<T> fetch​(T association)
        Description copied from interface: Stage.Session
        Asynchronously fetch an association that's configured for lazy loading.
         session.fetch(author.getBook()).thenAccept(book -> print(book.getTitle()))
         
        Specified by:
        fetch in interface Stage.Session
        Parameters:
        association - a lazy-loaded association
        Returns:
        the fetched association, via a CompletionStage
        See Also:
        Stage.fetch(Object), Hibernate.initialize(Object)
      • fetch

        public <E,​T> java.util.concurrent.CompletionStage<T> fetch​(E entity,
                                                                         jakarta.persistence.metamodel.Attribute<E,​T> field)
        Description copied from interface: Stage.Session
        Fetch a lazy property of the given entity, identified by a JPA attribute metamodel. Note that this feature is only supported in conjunction with the Hibernate bytecode enhancer.
         session.fetch(book, Book_.isbn).thenAccept(isbn -> print(isbn))
         
        Specified by:
        fetch in interface Stage.Session
      • unproxy

        public <T> java.util.concurrent.CompletionStage<T> unproxy​(T association)
        Description copied from interface: Stage.Session
        Asynchronously fetch an association that's configured for lazy loading, and unwrap the underlying entity implementation from any proxy.
         session.unproxy(author.getBook()).thenAccept(book -> print(book.getTitle()));
         
        Specified by:
        unproxy in interface Stage.Session
        Parameters:
        association - a lazy-loaded association
        Returns:
        the fetched association, via a CompletionStage
        See Also:
        Hibernate.unproxy(Object)
      • getReference

        public <T> T getReference​(java.lang.Class<T> entityClass,
                                  java.lang.Object id)
        Description copied from interface: Stage.Session
        Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. This method never results in access to the underlying data store, and thus might return a proxy that must be initialized explicitly using Stage.Session.fetch(Object).

        You should not use this method to determine if an instance exists (use Stage.Session.find(java.lang.Class<T>, java.lang.Object) instead). Use this only to retrieve an instance which you safely assume exists, where non-existence would be an actual error.

        Specified by:
        getReference in interface Stage.Session
        Parameters:
        entityClass - a persistent class
        id - a valid identifier of an existing persistent instance of the class
        Returns:
        the persistent instance or proxy
        See Also:
        EntityManager.getReference(Class, Object)
      • getReference

        public <T> T getReference​(T entity)
        Description copied from interface: Stage.Session
        Return the persistent instance with the same identity as the given instance, which might be detached, assuming 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 must be initialized explicitly using Stage.Session.fetch(Object).
        Specified by:
        getReference in interface Stage.Session
        Parameters:
        entity - a detached persistent instance
        Returns:
        the persistent instance or proxy
      • getLockMode

        public org.hibernate.LockMode getLockMode​(java.lang.Object entity)
        Description copied from interface: Stage.Session
        Determine the current lock mode of the given entity.
        Specified by:
        getLockMode in interface Stage.Session
      • contains

        public boolean contains​(java.lang.Object entity)
        Description copied from interface: Stage.Session
        Determine if the given instance belongs to this persistence context.
        Specified by:
        contains in interface Stage.Session
      • find

        public <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass,
                                                                java.lang.Object primaryKey)
        Description copied from interface: Stage.Session
        Asynchronously return 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 the associated instance. This method never returns an uninitialized instance.
         session.find(Book.class, id).thenAccept(book -> print(book.getTitle()));
         
        Specified by:
        find in interface Stage.Session
        Parameters:
        entityClass - The entity type
        primaryKey - an identifier
        Returns:
        a persistent instance or null via a CompletionStage
        See Also:
        EntityManager.find(Class, Object)
      • find

        public <T> java.util.concurrent.CompletionStage<java.util.List<T>> find​(java.lang.Class<T> entityClass,
                                                                                java.lang.Object... ids)
        Description copied from interface: Stage.Session
        Asynchronously return the persistent instances of the given entity class with the given identifiers, or null if there is no such persistent instance.
        Specified by:
        find in interface Stage.Session
        Parameters:
        entityClass - The entity type
        ids - the identifiers
        Returns:
        a list of persistent instances and nulls via a CompletionStage
      • find

        public <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass,
                                                                Identifier<T> id)
        Description copied from interface: Stage.Session
        Asynchronously return the persistent instance of the given entity class with the given natural identifiers, or null if there is no such persistent instance.
        Specified by:
        find in interface Stage.Session
        Parameters:
        entityClass - The entity type
        id - the natural identifier
        Returns:
        a persistent instance or null via a CompletionStage
      • find

        public <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass,
                                                                java.lang.Object primaryKey,
                                                                org.hibernate.LockMode lockMode)
        Description copied from interface: Stage.Session
        Asynchronously return the persistent instance of the given entity class with the given identifier, requesting the given LockMode.
        Specified by:
        find in interface Stage.Session
        Parameters:
        entityClass - The entity type
        primaryKey - an identifier
        lockMode - the requested LockMode
        Returns:
        a persistent instance or null via a CompletionStage
        See Also:
        Stage.Session.find(Class,Object), this discussion of lock modes
      • find

        public <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass,
                                                                java.lang.Object id,
                                                                jakarta.persistence.LockModeType lockModeType)
        Description copied from interface: Stage.Session
        Asynchronously return the persistent instance of the given entity class with the given identifier, requesting the given LockModeType.
        Specified by:
        find in interface Stage.Session
        Parameters:
        entityClass - The entity type
        id - an identifier
        lockModeType - the requested LockModeType
        Returns:
        a persistent instance or null via a CompletionStage
        See Also:
        Stage.Session.find(Class,Object), this discussion of lock modes
      • find

        public <T> java.util.concurrent.CompletionStage<T> find​(java.lang.Class<T> entityClass,
                                                                java.lang.Object primaryKey,
                                                                org.hibernate.LockOptions lockOptions)
      • find

        public <T> java.util.concurrent.CompletionStage<T> find​(jakarta.persistence.EntityGraph<T> entityGraph,
                                                                java.lang.Object id)
        Description copied from interface: Stage.Session
        Asynchronously return the persistent instance with the given identifier of an entity class, using the given EntityGraph as a fetch plan.
        Specified by:
        find in interface Stage.Session
        Parameters:
        entityGraph - an EntityGraph specifying the entity and associations to be fetched
        id - an identifier
        See Also:
        Stage.Session.find(Class,Object)
      • persist

        public java.util.concurrent.CompletionStage<java.lang.Void> persist​(java.lang.Object entity)
        Description copied from interface: Stage.Session
        Asynchronously persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the entity has assigned identifiers.)

        This operation cascades to associated instances if the association is mapped with CascadeType.PERSIST.

         session.persist(newBook).thenAccept(v -> session.flush());
         
        Specified by:
        persist in interface Stage.Session
        Parameters:
        entity - a transient instance of a persistent class
        See Also:
        EntityManager.persist(Object)
      • remove

        public java.util.concurrent.CompletionStage<java.lang.Void> remove​(java.lang.Object entity)
        Description copied from interface: Stage.Session
        Asynchronously remove a persistent instance from the datastore. The argument may be an instance associated with the receiving session or a transient instance with an identifier associated with existing persistent state.

        This operation cascades to associated instances if the association is mapped with CascadeType.REMOVE.

         session.delete(book).thenAccept(v -> session.flush());
         
        Specified by:
        remove in interface Stage.Session
        Parameters:
        entity - the managed persistent instance to be removed
        See Also:
        EntityManager.remove(Object)
      • merge

        public <T> java.util.concurrent.CompletionStage<T> merge​(T entity)
        Description copied from interface: Stage.Session
        Copy the state of the given object onto the persistent instance with the same identifier. If there is no such persistent instance currently associated with the session, it will be loaded. Return the persistent instance. Or, if the given instance is transient, save a copy of it and return the copy 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 with CascadeType.MERGE.

        Specified by:
        merge in interface Stage.Session
        Parameters:
        entity - a detached instance with state to be copied
        Returns:
        an updated persistent instance
        See Also:
        EntityManager.merge(Object)
      • merge

        @SafeVarargs
        public final <T> java.util.concurrent.CompletionStage<java.lang.Void> merge​(T... entity)
        Description copied from interface: Stage.Session
        Merge multiple entity instances at once.
        Specified by:
        merge in interface Stage.Session
        See Also:
        Stage.Session.merge(Object)
      • refresh

        public java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity)
        Description copied from interface: Stage.Session
        Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances, for example:
        • where a database trigger alters the object state after insert or update, or
        • after executing direct native SQL in the same session.
        Specified by:
        refresh in interface Stage.Session
        Parameters:
        entity - a managed persistent instance
        See Also:
        EntityManager.refresh(Object)
      • refresh

        public java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity,
                                                                            org.hibernate.LockMode lockMode)
        Description copied from interface: Stage.Session
        Re-read the state of the given instance from the underlying database, requesting the given LockMode.
        Specified by:
        refresh in interface Stage.Session
        Parameters:
        entity - a managed persistent entity instance
        lockMode - the requested lock mode
        See Also:
        Stage.Session.refresh(Object)
      • refresh

        public java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity,
                                                                            jakarta.persistence.LockModeType lockModeType)
        Description copied from interface: Stage.Session
        Re-read the state of the given instance from the underlying database, requesting the given LockModeType.
        Specified by:
        refresh in interface Stage.Session
        Parameters:
        entity - a managed persistent entity instance
        lockModeType - the requested lock mode
        See Also:
        Stage.Session.refresh(Object)
      • refresh

        public java.util.concurrent.CompletionStage<java.lang.Void> refresh​(java.lang.Object entity,
                                                                            org.hibernate.LockOptions lockOptions)
      • lock

        public java.util.concurrent.CompletionStage<java.lang.Void> lock​(java.lang.Object entity,
                                                                         org.hibernate.LockMode lockMode)
        Description copied from interface: Stage.Session
        Obtain the specified lock level upon the given object. For example, this operation may be used to:
        • perform a version check with LockMode.PESSIMISTIC_READ,
        • upgrade to a pessimistic lock with LockMode.PESSIMISTIC_WRITE,
        • force a version increment with LockMode.PESSIMISTIC_FORCE_INCREMENT,
        • schedule a version check just before the end of the transaction with LockMode.OPTIMISTIC, or
        • schedule a version increment just before the end of the transaction with LockMode.OPTIMISTIC_FORCE_INCREMENT.
        This operation cascades to associated instances if the association is mapped with CascadeType.LOCK.
        Specified by:
        lock in interface Stage.Session
        Parameters:
        entity - a managed persistent instance
        lockMode - the lock level
      • lock

        public java.util.concurrent.CompletionStage<java.lang.Void> lock​(java.lang.Object entity,
                                                                         jakarta.persistence.LockModeType lockModeType)
        Description copied from interface: Stage.Session
        Obtain the specified lock level upon the given object. For example, this operation may be used to:
        • perform a version check with LockModeType.PESSIMISTIC_READ,
        • upgrade to a pessimistic lock with LockModeType.PESSIMISTIC_WRITE,
        • force a version increment with LockModeType.PESSIMISTIC_FORCE_INCREMENT,
        • schedule a version check just before the end of the transaction with LockModeType.OPTIMISTIC, or
        • schedule a version increment just before the end of the transaction with LockModeType.OPTIMISTIC_FORCE_INCREMENT.
        This operation cascades to associated instances if the association is mapped with CascadeType.LOCK.
        Specified by:
        lock in interface Stage.Session
        Parameters:
        entity - a managed persistent instance
        lockModeType - the lock level
      • lock

        public java.util.concurrent.CompletionStage<java.lang.Void> lock​(java.lang.Object entity,
                                                                         org.hibernate.LockOptions lockOptions)
      • getFlushMode

        public org.hibernate.FlushMode getFlushMode()
        Description copied from interface: Stage.Session
        Get the current flush mode for this session.
        Specified by:
        getFlushMode in interface Stage.Session
        Returns:
        the flush mode
      • setFlushMode

        public Stage.Session setFlushMode​(org.hibernate.FlushMode flushMode)
        Description copied from interface: Stage.Session
        Set the flush mode for this session.

        The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.

        For a logically "read only" session, it is reasonable to set the session's flush mode to FlushMode.MANUAL at the start of the session (in order to achieve some extra performance).

        Specified by:
        setFlushMode in interface Stage.Session
        Parameters:
        flushMode - the new flush mode
      • setFlushMode

        public Stage.Session setFlushMode​(jakarta.persistence.FlushModeType flushModeType)
        Description copied from interface: Stage.Session
        Set the flush mode for this session.

        The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.

        Specified by:
        setFlushMode in interface Stage.Session
        Parameters:
        flushModeType - the new flush mode
      • setDefaultReadOnly

        public Stage.Session setDefaultReadOnly​(boolean readOnly)
        Description copied from interface: Stage.Session
        Change the default for entities and proxies loaded into this session from modifiable to read-only mode, or from modifiable to read-only mode.

        Read-only entities are not dirty-checked and snapshots of persistent state are not maintained. Read-only entities can be modified, but changes are not persisted.

        Specified by:
        setDefaultReadOnly in interface Stage.Session
        See Also:
        Session.setDefaultReadOnly(boolean)
      • isDefaultReadOnly

        public boolean isDefaultReadOnly()
        Specified by:
        isDefaultReadOnly in interface Stage.Session
        Returns:
        the default read-only mode for entities and proxies loaded in this session
      • setReadOnly

        public Stage.Session setReadOnly​(java.lang.Object entityOrProxy,
                                         boolean readOnly)
        Description copied from interface: Stage.Session
        Set 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 changes are not persisted.
        Specified by:
        setReadOnly in interface Stage.Session
        See Also:
        Session.setReadOnly(Object, boolean)
      • isReadOnly

        public boolean isReadOnly​(java.lang.Object entityOrProxy)
        Description copied from interface: Stage.Session
        Is the specified entity or proxy read-only?
        Specified by:
        isReadOnly in interface Stage.Session
        See Also:
        Session.isReadOnly(Object)
      • getCacheMode

        public org.hibernate.CacheMode getCacheMode()
        Description copied from interface: Stage.Session
        Get the current cache mode.
        Specified by:
        getCacheMode in interface Stage.Session
        Returns:
        The current cache mode.
      • setCacheMode

        public Stage.Session setCacheMode​(org.hibernate.CacheMode cacheMode)
        Description copied from interface: Stage.Session
        Set the cache mode for this session.

        The cache mode determines the manner in which this session interacts with the second level cache.

        Specified by:
        setCacheMode in interface Stage.Session
        Parameters:
        cacheMode - The new cache mode.
      • setCacheStoreMode

        public Stage.Session setCacheStoreMode​(jakarta.persistence.CacheStoreMode cacheStoreMode)
        Description copied from interface: Stage.Session
        Set the CacheStoreMode for this session.
        Specified by:
        setCacheStoreMode in interface Stage.Session
        Parameters:
        cacheStoreMode - The new cache store mode.
      • setCacheRetrieveMode

        public Stage.Session setCacheRetrieveMode​(jakarta.persistence.CacheRetrieveMode cacheRetrieveMode)
        Description copied from interface: Stage.Session
        Set the CacheRetrieveMode for this session.
        Specified by:
        setCacheRetrieveMode in interface Stage.Session
        Parameters:
        cacheRetrieveMode - The new cache retrieve mode.
      • setBatchSize

        public Stage.Session setBatchSize​(java.lang.Integer batchSize)
        Description copied from interface: Stage.Session
        Set the session-level batch size, overriding the batch size set by the configuration property hibernate.jdbc.batch_size.
        Specified by:
        setBatchSize in interface Stage.Session
      • getBatchSize

        public java.lang.Integer getBatchSize()
        Description copied from interface: Stage.Session
        The session-level batch size, or null if it has not been overridden.
        Specified by:
        getBatchSize in interface Stage.Session
      • detach

        public Stage.Session detach​(java.lang.Object entity)
        Description copied from interface: Stage.Session
        Remove 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.

        Specified by:
        detach in interface Stage.Session
        Parameters:
        entity - The entity to evict
        See Also:
        EntityManager.detach(Object)
      • clear

        public Stage.Session clear()
        Description copied from interface: Stage.Session
        Completely clear the session. Detach all persistent instances and cancel all pending insertions, updates and deletions.
        Specified by:
        clear in interface Stage.Session
        See Also:
        EntityManager.clear()
      • enableFetchProfile

        public Stage.Session enableFetchProfile​(java.lang.String name)
        Description copied from interface: Stage.Session
        Enable a particular fetch profile on this session, or do nothing if requested fetch profile is already enabled.
        Specified by:
        enableFetchProfile in interface Stage.Session
        Parameters:
        name - The name of the fetch profile to be enabled.
        See Also:
        for discussion of this feature
      • disableFetchProfile

        public Stage.Session disableFetchProfile​(java.lang.String name)
        Description copied from interface: Stage.Session
        Disable a particular fetch profile on this session, or do nothing if the requested fetch profile is not enabled.
        Specified by:
        disableFetchProfile in interface Stage.Session
        Parameters:
        name - The name of the fetch profile to be disabled.
        See Also:
        for discussion of this feature
      • isFetchProfileEnabled

        public boolean isFetchProfileEnabled​(java.lang.String name)
        Description copied from interface: Stage.Session
        Determine if the fetch profile with the given name is enabled for this session.
        Specified by:
        isFetchProfileEnabled in interface Stage.Session
        Parameters:
        name - The name of the profile to be checked.
        Returns:
        True if fetch profile is enabled; false if not.
        See Also:
        for discussion of this feature
      • enableFilter

        public org.hibernate.Filter enableFilter​(java.lang.String filterName)
        Description copied from interface: Stage.Session
        Enable the named filter for this session.
        Specified by:
        enableFilter in interface Stage.Session
        Parameters:
        filterName - The name of the filter to be enabled.
        Returns:
        The Filter instance representing the enabled filter.
      • disableFilter

        public void disableFilter​(java.lang.String filterName)
        Description copied from interface: Stage.Session
        Disable the named filter for this session.
        Specified by:
        disableFilter in interface Stage.Session
        Parameters:
        filterName - The name of the filter to be disabled.
      • getEnabledFilter

        public org.hibernate.Filter getEnabledFilter​(java.lang.String filterName)
        Description copied from interface: Stage.Session
        Retrieve a currently enabled filter by name.
        Specified by:
        getEnabledFilter in interface Stage.Session
        Parameters:
        filterName - The name of the filter to be retrieved.
        Returns:
        The Filter instance representing the enabled filter.
      • withTransaction

        public <T> java.util.concurrent.CompletionStage<T> withTransaction​(java.util.function.Function<Stage.Transaction,​java.util.concurrent.CompletionStage<T>> work)
        Description copied from interface: Stage.Session
        Performs the given work within the scope of a database transaction, automatically flushing the session. The transaction will be rolled back if the work completes with an uncaught exception, or if Stage.Transaction.markForRollback() is called.

        The resulting Stage.Transaction object may also be obtained via Stage.Session.currentTransaction().

      • If there is already a transaction associated with this session, the work is executed in the context of the existing transaction, and no new transaction is initiated.
      • If there is no transaction associated with this session, a new transaction is started, and the work is executed in the context of the new transaction.
Specified by:
withTransaction in interface Stage.Session
Parameters:
work - a function which accepts Stage.Transaction and returns the result of the work as a CompletionStage.
See Also:
Stage.SessionFactory.withTransaction(BiFunction)