Class SessionLazyDelegator

java.lang.Object
org.hibernate.engine.spi.SessionLazyDelegator
All Implemented Interfaces:
EntityManager, Closeable, Serializable, AutoCloseable, QueryProducer, Session, SharedSessionContract

public class SessionLazyDelegator extends Object implements Session
This helper class allows decorating a Session instance, while the instance itself is lazily provided via a Supplier. When the decorated instance is readily available, one should prefer using SessionDelegatorBaseImpl.

Another difference with SessionDelegatorBaseImpl is that this type only implements Session.

Author:
Sanne Grinovero
See Also:
  • Constructor Details

    • SessionLazyDelegator

      public SessionLazyDelegator(Supplier<Session> lazySessionLookup)
  • Method Details

    • getFactory

      public SessionFactory getFactory()
      Description copied from interface: SharedSessionContract
      The factory which created this session.
      Specified by:
      getFactory in interface SharedSessionContract
    • flush

      public void flush()
      Description copied from interface: Session
      Force 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:
      flush in interface EntityManager
      Specified by:
      flush in interface Session
    • setFlushMode

      public void setFlushMode(FlushModeType flushMode)
      Description copied from interface: Session
      Set 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:
      setFlushMode in interface EntityManager
      Specified by:
      setFlushMode in interface Session
      Parameters:
      flushMode - the new FlushModeType
      See Also:
    • setHibernateFlushMode

      public void setHibernateFlushMode(FlushMode flushMode)
      Description copied from interface: Session
      Set 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.MANUAL at the start of the session in order to avoid some unnecessary work.

      Note that FlushMode defines more options than FlushModeType.

      Specified by:
      setHibernateFlushMode in interface Session
      Parameters:
      flushMode - the new FlushMode
    • getFlushMode

      public FlushModeType getFlushMode()
      Description copied from interface: Session
      Get the current JPA flush mode for this session.
      Specified by:
      getFlushMode in interface EntityManager
      Specified by:
      getFlushMode in interface Session
      Returns:
      the FlushModeType currently in effect
    • getHibernateFlushMode

      public FlushMode getHibernateFlushMode()
      Description copied from interface: Session
      Get the current flush mode for this session.
      Specified by:
      getHibernateFlushMode in interface Session
      Returns:
      the FlushMode currently in effect
    • setCacheMode

      public void setCacheMode(CacheMode cacheMode)
      Description copied from interface: Session
      Set the current cache mode for this session.

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

      Specified by:
      setCacheMode in interface Session
      Parameters:
      cacheMode - the new cache mode
    • setCacheRetrieveMode

      public void setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode)
      Description copied from interface: Session
      Enable or disable reads from the second-level cache.
      Specified by:
      setCacheRetrieveMode in interface Session
      Parameters:
      cacheRetrieveMode - a JPA-defined CacheRetrieveMode
      See Also:
    • setCacheStoreMode

      public void setCacheStoreMode(CacheStoreMode cacheStoreMode)
      Description copied from interface: Session
      Enable or disable writes to the second-level cache.
      Specified by:
      setCacheStoreMode in interface Session
      Parameters:
      cacheStoreMode - a JPA-defined CacheStoreMode
      See Also:
    • getCacheStoreMode

      public CacheStoreMode getCacheStoreMode()
      Description copied from interface: Session
      The JPA-defined CacheStoreMode.
      Specified by:
      getCacheStoreMode in interface Session
      See Also:
    • getCacheRetrieveMode

      public CacheRetrieveMode getCacheRetrieveMode()
      Description copied from interface: Session
      The JPA-defined CacheRetrieveMode.
      Specified by:
      getCacheRetrieveMode in interface Session
      See Also:
    • getCacheMode

      public CacheMode getCacheMode()
      Description copied from interface: Session
      Get the current cache mode for this session.
      Specified by:
      getCacheMode in interface Session
      Returns:
      the current cache mode
    • getSessionFactory

      public SessionFactory getSessionFactory()
      Description copied from interface: Session
      Get the session factory which created this session.
      Specified by:
      getSessionFactory in interface Session
      Returns:
      the session factory
      See Also:
    • cancelQuery

      public void cancelQuery()
      Description copied from interface: Session
      Cancel the execution of the current query.

      This is the sole method on session which may be safely called from another thread.

      Specified by:
      cancelQuery in interface Session
    • isDirty

      public boolean isDirty()
      Description copied from interface: Session
      Does this session contain any changes which must be synchronized with the database? In other words, would any DML operations be executed if we flushed this session?
      Specified by:
      isDirty in interface Session
      Returns:
      true if the session contains pending changes; false otherwise.
    • isDefaultReadOnly

      public boolean isDefaultReadOnly()
      Description copied from interface: Session
      Will 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:
      isDefaultReadOnly in interface Session
      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: 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.

      When a proxy is initialized, the loaded entity will have the same read-only/modifiable setting as the uninitialized proxy has, regardless of the session's current setting.

      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 this session's read-only/modifiable setting for all entities and proxies loaded by a certain Query use Query.setReadOnly(boolean).

      Specified by:
      setDefaultReadOnly in interface Session
      Parameters:
      readOnly - true, the default for loaded entities/proxies is read-only; false, the default for loaded entities/proxies is modifiable
      See Also:
    • getIdentifier

      public Object getIdentifier(Object object)
      Description copied from interface: Session
      Return 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:
      getIdentifier in interface Session
      Parameters:
      object - a persistent instance associated with this session
      Returns:
      the identifier
    • contains

      public boolean contains(String entityName, Object object)
      Description copied from interface: Session
      Determine if the given entity is associated with this session.
      Specified by:
      contains in interface Session
      Parameters:
      entityName - the entity name
      object - an instance of a persistent class
      Returns:
      true if the given instance is associated with this Session
    • detach

      public void detach(Object object)
      Description copied from interface: 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 EntityManager
      Specified by:
      detach in interface Session
      Parameters:
      object - the managed instance to detach
    • evict

      public void evict(Object object)
      Description copied from interface: 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.

      This operation is a synonym for Session.detach(Object).

      Specified by:
      evict in interface Session
      Parameters:
      object - the managed entity to evict
    • load

      @Deprecated public <T> T load(Class<T> theClass, Object id, LockMode lockMode)
      Deprecated.
      Description copied from interface: Session
      Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

      Convenient form of Session.load(Class, Object, LockOptions).

      Specified by:
      load in interface Session
      Parameters:
      theClass - a persistent class
      id - a valid identifier of an existing persistent instance of the class
      lockMode - the lock level
      Returns:
      the persistent instance or proxy
      See Also:
    • load

      @Deprecated public <T> T load(Class<T> theClass, Object id, LockOptions lockOptions)
      Deprecated.
      Description copied from interface: Session
      Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.
      Specified by:
      load in interface Session
      Parameters:
      theClass - a persistent class
      id - a valid identifier of an existing persistent instance of the class
      lockOptions - contains the lock level
      Returns:
      the persistent instance or proxy
    • load

      @Deprecated public Object load(String entityName, Object id, LockMode lockMode)
      Deprecated.
      Description copied from interface: Session
      Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

      Convenient form of Session.load(String, Object, LockOptions).

      Specified by:
      load in interface Session
      Parameters:
      entityName - the entity name
      id - a valid identifier of an existing persistent instance of the class
      lockMode - the lock level
      Returns:
      the persistent instance or proxy
      See Also:
    • load

      @Deprecated public Object load(String entityName, Object id, LockOptions lockOptions)
      Deprecated.
      Description copied from interface: Session
      Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.
      Specified by:
      load in interface Session
      Parameters:
      entityName - the entity name
      id - a valid identifier of an existing persistent instance of the class
      lockOptions - contains the lock level
      Returns:
      the persistent instance or proxy
    • load

      @Deprecated public <T> T load(Class<T> theClass, Object id)
      Deprecated.
      Description copied from interface: Session
      Return the persistent instance of the given entity class with the given identifier, making the assumption that the instance exists in the database. This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed.

      You should not use this method to determine if an instance exists in the database (use get() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.

      This operation is very similar to Session.getReference(Class, Object).

      Specified by:
      load in interface Session
      Parameters:
      theClass - a persistent class
      id - a valid identifier of an existing persistent instance of the class
      Returns:
      the persistent instance or proxy
    • load

      @Deprecated public Object load(String entityName, Object id)
      Deprecated.
      Description copied from interface: Session
      Return the persistent instance of the given entity class with the given identifier, making the assumption that the instance exists in the database. This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed.

      You should not use this method to determine if an instance exists in the database (use get() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.

      Specified by:
      load in interface Session
      Parameters:
      entityName - the entity name
      id - a valid identifier of an existing persistent instance of the class
      Returns:
      the persistent instance or proxy
    • load

      public void load(Object object, Object id)
      Description copied from interface: Session
      Read the persistent state associated with the given identifier into the given transient instance.
      Specified by:
      load in interface Session
    • replicate

      @Deprecated public void replicate(Object object, ReplicationMode replicationMode)
      Deprecated.
      Description copied from interface: Session
      Persist the state of the given detached instance, reusing the current identifier value. This operation cascades to associated instances if the association is mapped with CascadeType.REPLICATE.
      Specified by:
      replicate in interface Session
      Parameters:
      object - a detached instance of a persistent class
      replicationMode - the replication mode to use
    • replicate

      @Deprecated public void replicate(String entityName, Object object, ReplicationMode replicationMode)
      Deprecated.
      Description copied from interface: Session
      Persist the state of the given detached instance, reusing the current identifier value. This operation cascades to associated instances if the association is mapped with CascadeType.REPLICATE.
      Specified by:
      replicate in interface Session
      Parameters:
      entityName - the entity name
      object - a detached instance of a persistent class
      replicationMode - the replication mode to use
    • save

      @Deprecated public Object save(Object object)
      Deprecated.
      Description copied from interface: Session
      Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.) This operation cascades to associated instances if the association is mapped with CascadeType.SAVE_UPDATE.

      This operation is very similar to Session.persist(Object).

      Specified by:
      save in interface Session
      Parameters:
      object - a transient instance of a persistent class
      Returns:
      the generated identifier
    • save

      @Deprecated public Object save(String entityName, Object object)
      Deprecated.
      Description copied from interface: Session
      Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.) This operation cascades to associated instances if the association is mapped with CascadeType.SAVE_UPDATE.
      Specified by:
      save in interface Session
      Parameters:
      entityName - the entity name
      object - a transient instance of a persistent class
      Returns:
      the generated identifier
    • saveOrUpdate

      @Deprecated public void saveOrUpdate(Object object)
      Deprecated.
      Description copied from interface: Session
      Either Session.save(Object) or Session.update(Object) the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

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

      Specified by:
      saveOrUpdate in interface Session
      Parameters:
      object - a transient or detached instance containing new or updated state
      See Also:
    • saveOrUpdate

      @Deprecated public void saveOrUpdate(String entityName, Object object)
      Deprecated.
      Description copied from interface: Session
      Either Session.save(String, Object) or Session.update(String, Object) the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

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

      Specified by:
      saveOrUpdate in interface Session
      Parameters:
      entityName - the entity name
      object - a transient or detached instance containing new or updated state
      See Also:
    • update

      @Deprecated public void update(Object object)
      Deprecated.
      Description copied from interface: Session
      Update the persistent instance with the identifier of the given detached instance. If there is a persistent instance with the same identifier, an exception is thrown. This operation cascades to associated instances if the association is mapped with CascadeType.SAVE_UPDATE.
      Specified by:
      update in interface Session
      Parameters:
      object - a detached instance containing updated state
    • update

      @Deprecated public void update(String entityName, Object object)
      Deprecated.
      Description copied from interface: Session
      Update the persistent instance with the identifier of the given detached instance. If there is a persistent instance with the same identifier, an exception is thrown. This operation cascades to associated instances if the association is mapped with CascadeType.SAVE_UPDATE.
      Specified by:
      update in interface Session
      Parameters:
      entityName - the entity name
      object - a detached instance containing updated state
    • merge

      public <T> T merge(T object)
      Description copied from interface: Session
      Copy 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 with CascadeType.MERGE.
      Specified by:
      merge in interface EntityManager
      Specified by:
      merge in interface Session
      Parameters:
      object - a detached instance with state to be copied
      Returns:
      an updated persistent instance
    • merge

      public <T> T merge(String entityName, T object)
      Description copied from interface: Session
      Copy 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 with CascadeType.MERGE.
      Specified by:
      merge in interface Session
      Parameters:
      entityName - the entity name
      object - a detached instance with state to be copied
      Returns:
      an updated persistent instance
    • persist

      public void persist(Object object)
      Description copied from interface: Session
      Make 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 an entity 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:
      persist in interface EntityManager
      Specified by:
      persist in interface Session
      Parameters:
      object - a transient instance to be made persistent
    • persist

      public void persist(String entityName, Object object)
      Description copied from interface: Session
      Make 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:
      persist in interface Session
      Parameters:
      entityName - the entity name
      object - a transient instance to be made persistent
    • delete

      @Deprecated public void delete(Object object)
      Deprecated.
      Description copied from interface: Session
      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.
      Specified by:
      delete in interface Session
      Parameters:
      object - the instance to be removed
    • delete

      @Deprecated public void delete(String entityName, Object object)
      Deprecated.
      Description copied from interface: Session
      Remove a persistent instance from the datastore. The second 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.
      Specified by:
      delete in interface Session
      Parameters:
      entityName - the entity name for the instance to be removed.
      object - the instance to be removed
    • lock

      public void lock(Object object, LockMode lockMode)
      Description copied from interface: Session
      Obtain the specified lock level on the given managed instance associated with this session. This operation may be used to:

      If the requested lock mode is already held on the given entity, this operation has no effect.

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

      The modes LockMode.WRITE and LockMode.UPGRADE_SKIPLOCKED are not legal arguments to lock().

      Specified by:
      lock in interface Session
      Parameters:
      object - a persistent instance
      lockMode - the lock level
    • lock

      @Deprecated public void lock(String entityName, Object object, LockMode lockMode)
      Deprecated.
      Description copied from interface: Session
      Obtain the specified lock level on the given managed instance associated with this session. This may be used to:

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

      Specified by:
      lock in interface Session
      Parameters:
      entityName - the name of the entity
      object - a persistent instance associated with this session
      lockMode - the lock level
    • lock

      public void lock(Object object, LockOptions lockOptions)
      Description copied from interface: Session
      Obtain a lock on the given managed instance associated with this session, using the given lock options.

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

      Specified by:
      lock in interface Session
      Parameters:
      object - a persistent instance
      lockOptions - the lock options
    • buildLockRequest

      @Deprecated public Session.LockRequest buildLockRequest(LockOptions lockOptions)
      Deprecated.
      Description copied from interface: Session
      Build a new lock request that specifies:

      Timeout and scope are ignored if the specified LockMode represents a flavor of optimistic locking.

      Call Session.LockRequest.lock(Object) to actually obtain the requested lock on a managed entity instance.

      Specified by:
      buildLockRequest in interface Session
      Parameters:
      lockOptions - contains the lock level
      Returns:
      a Session.LockRequest that can be used to lock any given object.
    • refresh

      public void refresh(Object object)
      Description copied from interface: Session
      Reread 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 Blob or Clob.

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

      This operation requests LockMode.READ. To obtain a stronger lock, call Session.refresh(Object, LockMode).

      Specified by:
      refresh in interface EntityManager
      Specified by:
      refresh in interface Session
      Parameters:
      object - a persistent instance associated with this session
    • refresh

      @Deprecated public void refresh(String entityName, Object object)
      Deprecated.
      Description copied from interface: Session
      Reread 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 Blob or Clob.

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

      Specified by:
      refresh in interface Session
      Parameters:
      entityName - the name of the entity
      object - a persistent instance associated with this session
    • refresh

      public void refresh(Object object, LockMode lockMode)
      Description copied from interface: Session
      Reread the state of the given managed instance from the underlying database, obtaining the given LockMode.

      Convenient form of Session.refresh(Object, LockOptions)

      Specified by:
      refresh in interface Session
      Parameters:
      object - a persistent instance associated with this session
      lockMode - the lock mode to use
      See Also:
    • refresh

      public void refresh(Object object, LockOptions lockOptions)
      Description copied from interface: Session
      Reread the state of the given managed instance from the underlying database, obtaining the given LockMode.
      Specified by:
      refresh in interface Session
      Parameters:
      object - a persistent instance associated with this session
      lockOptions - contains the lock mode to use
    • refresh

      @Deprecated public void refresh(String entityName, Object object, LockOptions lockOptions)
      Deprecated.
      Description copied from interface: Session
      Reread the state of the given managed instance from the underlying database, obtaining the given LockMode.
      Specified by:
      refresh in interface Session
      Parameters:
      entityName - the name of the entity
      object - a persistent instance associated with this session
      lockOptions - contains the lock mode to use
    • remove

      public void remove(Object object)
      Description copied from interface: Session
      Mark a persistence instance associated with this session for removal from the underlying database. Ths operation cascades to associated instances if the association is mapped CascadeType.REMOVE.
      Specified by:
      remove in interface EntityManager
      Specified by:
      remove in interface Session
      Parameters:
      object - the managed persistent instance to remove
    • getCurrentLockMode

      public LockMode getCurrentLockMode(Object object)
      Description copied from interface: Session
      Determine the current LockMode of the given managed instance associated with this session.
      Specified by:
      getCurrentLockMode in interface Session
      Parameters:
      object - a persistent instance associated with this session
      Returns:
      the current lock mode
    • clear

      public void clear()
      Description copied from interface: Session
      Completely clear the session. Evict all loaded instances and cancel all pending saves, updates and deletions. Do not close open iterators or instances of ScrollableResults.
      Specified by:
      clear in interface EntityManager
      Specified by:
      clear in interface Session
    • get

      public <T> T get(Class<T> entityType, Object id)
      Description copied from interface: Session
      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 that instance. This method never returns an uninitialized instance.

      This operation is very similar to EntityManager.find(Class, Object).

      The object returned by get() or find() is either an unproxied instance of the given entity class, of 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 mode LockMode.READ.

      To bypass the second-level cache, and ensure that the state is read from the database, either:

      Specified by:
      get in interface Session
      Parameters:
      entityType - the entity type
      id - an identifier
      Returns:
      a persistent instance or null
    • get

      public <T> T get(Class<T> entityType, Object id, LockMode lockMode)
      Description copied from interface: Session
      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 that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists.

      Convenient form of Session.get(Class, Object, LockOptions).

      This operation is very similar to EntityManager.find(Class, Object, jakarta.persistence.LockModeType).

      Specified by:
      get in interface Session
      Parameters:
      entityType - the entity type
      id - an identifier
      lockMode - the lock mode
      Returns:
      a persistent instance or null
      See Also:
    • get

      public <T> T get(Class<T> entityType, Object id, LockOptions lockOptions)
      Description copied from interface: Session
      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 that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists.
      Specified by:
      get in interface Session
      Parameters:
      entityType - the entity type
      id - an identifier
      lockOptions - the lock mode
      Returns:
      a persistent instance or null
    • get

      public Object get(String entityName, Object id)
      Description copied from interface: Session
      Return the persistent instance of the given named entity 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.
      Specified by:
      get in interface Session
      Parameters:
      entityName - the entity name
      id - an identifier
      Returns:
      a persistent instance or null
    • get

      public Object get(String entityName, Object id, LockMode lockMode)
      Description copied from interface: Session
      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 that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists.

      Convenient form of Session.get(String, Object, LockOptions)

      Specified by:
      get in interface Session
      Parameters:
      entityName - the entity name
      id - an identifier
      lockMode - the lock mode
      Returns:
      a persistent instance or null
      See Also:
    • get

      public Object get(String entityName, Object id, LockOptions lockOptions)
      Description copied from interface: Session
      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 that instance. This method never returns an uninitialized instance. Obtain the specified lock mode if the instance exists.
      Specified by:
      get in interface Session
      Parameters:
      entityName - the entity name
      id - an identifier
      lockOptions - contains the lock mode
      Returns:
      a persistent instance or null
    • getEntityName

      public String getEntityName(Object object)
      Description copied from interface: Session
      Return the entity name for a persistent entity.
      Specified by:
      getEntityName in interface Session
      Parameters:
      object - a persistent entity associated with this session
      Returns:
      the entity name
    • getReference

      public <T> T getReference(Class<T> entityType, Object id)
      Description copied from interface: Session
      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. 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 method Hibernate.unproxy(Object, Class) is the recommended way to narrow the type of a proxy object. Alternatively, a new reference may be obtained by simply calling getReference() 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:
      getReference in interface EntityManager
      Specified by:
      getReference in interface Session
      Parameters:
      entityType - the entity type
      id - the identifier of a persistent instance that exists in the database
      Returns:
      the persistent instance or proxy
    • getReference

      public Object getReference(String entityName, Object id)
      Description copied from interface: Session
      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. 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:
      getReference in interface Session
      Parameters:
      entityName - the entity name
      id - the identifier of a persistent instance that exists in the database
      Returns:
      the persistent instance or proxy
    • getReference

      public <T> T getReference(T object)
      Description copied from interface: Session
      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. 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:
      getReference in interface Session
      Parameters:
      object - a detached persistent instance
      Returns:
      the persistent instance or proxy
    • byId

      public <T> IdentifierLoadAccess<T> byId(String entityName)
      Description copied from interface: Session
      Create an IdentifierLoadAccess instance to retrieve an instance of the named entity type by its primary key.
      Specified by:
      byId in interface Session
      Parameters:
      entityName - the entity name of the entity type to be retrieved
      Returns:
      an instance of IdentifierLoadAccess for executing the lookup
    • byMultipleIds

      public <T> MultiIdentifierLoadAccess<T> byMultipleIds(Class<T> entityClass)
      Description copied from interface: Session
      Create a MultiIdentifierLoadAccess instance to retrieve multiple instances of the given entity type by their primary key values, using batching.
      Specified by:
      byMultipleIds in interface Session
      Parameters:
      entityClass - the entity type to be retrieved
      Returns:
      an instance of MultiIdentifierLoadAccess for executing the lookup
    • byMultipleIds

      public <T> MultiIdentifierLoadAccess<T> byMultipleIds(String entityName)
      Description copied from interface: Session
      Create a MultiIdentifierLoadAccess instance to retrieve multiple instances of the named entity type by their primary key values, using batching.
      Specified by:
      byMultipleIds in interface Session
      Parameters:
      entityName - the entity name of the entity type to be retrieved
      Returns:
      an instance of MultiIdentifierLoadAccess for executing the lookup
    • byId

      public <T> IdentifierLoadAccess<T> byId(Class<T> entityClass)
      Description copied from interface: Session
      Create an IdentifierLoadAccess instance to retrieve an instance of the given entity type by its primary key.
      Specified by:
      byId in interface Session
      Parameters:
      entityClass - the entity type to be retrieved
      Returns:
      an instance of IdentifierLoadAccess for executing the lookup
    • byNaturalId

      public <T> NaturalIdLoadAccess<T> byNaturalId(String entityName)
      Description copied from interface: Session
      Create a NaturalIdLoadAccess instance 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 annotated NaturalId.
      Specified by:
      byNaturalId in interface Session
      Parameters:
      entityName - the entity name of the entity type to be retrieved
      Returns:
      an instance of NaturalIdLoadAccess for executing the lookup
    • byNaturalId

      public <T> NaturalIdLoadAccess<T> byNaturalId(Class<T> entityClass)
      Description copied from interface: Session
      Create a NaturalIdLoadAccess instance 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 annotated NaturalId.
      Specified by:
      byNaturalId in interface Session
      Parameters:
      entityClass - the entity type to be retrieved
      Returns:
      an instance of NaturalIdLoadAccess for executing the lookup
    • bySimpleNaturalId

      public <T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(String entityName)
      Description copied from interface: Session
      Create a SimpleNaturalIdLoadAccess instance 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 annotated NaturalId.
      Specified by:
      bySimpleNaturalId in interface Session
      Parameters:
      entityName - the entity name of the entity type to be retrieved
      Returns:
      an instance of SimpleNaturalIdLoadAccess for executing the lookup
    • bySimpleNaturalId

      public <T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(Class<T> entityClass)
      Description copied from interface: Session
      Create a SimpleNaturalIdLoadAccess instance 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 annotated NaturalId.
      Specified by:
      bySimpleNaturalId in interface Session
      Parameters:
      entityClass - the entity type to be retrieved
      Returns:
      an instance of SimpleNaturalIdLoadAccess for executing the lookup
    • byMultipleNaturalId

      public <T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(Class<T> entityClass)
      Description copied from interface: Session
      Create a MultiIdentifierLoadAccess instance to retrieve multiple instances of the given entity type by their by natural id values, using batching.
      Specified by:
      byMultipleNaturalId in interface Session
      Parameters:
      entityClass - the entity type to be retrieved
      Returns:
      an instance of NaturalIdMultiLoadAccess for executing the lookup
    • byMultipleNaturalId

      public <T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(String entityName)
      Description copied from interface: Session
      Create a MultiIdentifierLoadAccess instance to retrieve multiple instances of the named entity type by their by natural id values, using batching.
      Specified by:
      byMultipleNaturalId in interface Session
      Parameters:
      entityName - the entity name of the entity type to be retrieved
      Returns:
      an instance of NaturalIdMultiLoadAccess for executing the lookup
    • enableFilter

      public Filter enableFilter(String filterName)
      Description copied from interface: SharedSessionContract
      Enable the named filter for this current session.

      The returned Filter object 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:
      enableFilter in interface Session
      Specified by:
      enableFilter in interface SharedSessionContract
      Parameters:
      filterName - the name of the filter to be enabled.
      Returns:
      the Filter instance representing the enabled filter.
      See Also:
    • getEnabledFilter

      public Filter getEnabledFilter(String filterName)
      Description copied from interface: SharedSessionContract
      Retrieve a currently enabled filter by name.
      Specified by:
      getEnabledFilter in interface Session
      Specified by:
      getEnabledFilter in interface SharedSessionContract
      Parameters:
      filterName - the name of the filter to be retrieved.
      Returns:
      the Filter instance representing the enabled filter.
    • disableFilter

      public void disableFilter(String filterName)
      Description copied from interface: SharedSessionContract
      Disable the named filter for the current session.
      Specified by:
      disableFilter in interface Session
      Specified by:
      disableFilter in interface SharedSessionContract
      Parameters:
      filterName - the name of the filter to be disabled.
    • getStatistics

      public SessionStatistics getStatistics()
      Description copied from interface: Session
      Get the statistics for this session.
      Specified by:
      getStatistics in interface Session
      Returns:
      the session statistics being collected for this session
    • isReadOnly

      public boolean isReadOnly(Object entityOrProxy)
      Description copied from interface: Session
      Is 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:
      isReadOnly in interface Session
      Parameters:
      entityOrProxy - an entity or proxy
      Returns:
      true if the entity or proxy is read-only, false if the entity or proxy is modifiable.
      See Also:
    • setReadOnly

      public void setReadOnly(Object entityOrProxy, boolean readOnly)
      Description copied from interface: 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.

      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 this session's read-only/modifiable setting for entities and proxies loaded by a Query use Query.setReadOnly(boolean)

      Specified by:
      setReadOnly in interface Session
      Parameters:
      entityOrProxy - an entity or proxy
      readOnly - true if the entity or proxy should be made read-only; false if the entity or proxy should be made modifiable
      See Also:
    • isFetchProfileEnabled

      public boolean isFetchProfileEnabled(String name) throws UnknownProfileException
      Description copied from interface: Session
      Is the fetch profile with the given name enabled in this session?
      Specified by:
      isFetchProfileEnabled in interface Session
      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

      public void enableFetchProfile(String name) throws UnknownProfileException
      Description copied from interface: Session
      Enable 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:
      enableFetchProfile in interface Session
      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

      public void disableFetchProfile(String name) throws UnknownProfileException
      Description copied from interface: Session
      Disable 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:
      disableFetchProfile in interface Session
      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

      public LobHelper getLobHelper()
      Description copied from interface: Session
      Obtain a factory for instances of Blob and Clob.
      Specified by:
      getLobHelper in interface Session
      Returns:
      an instance of LobHelper
    • sessionWithOptions

      public SharedSessionBuilder sessionWithOptions()
      Description copied from interface: Session
      Obtain a Session builder with the ability to copy certain information from this session.
      Specified by:
      sessionWithOptions in interface Session
      Returns:
      the session builder
    • addEventListeners

      public void addEventListeners(SessionEventListener... listeners)
      Description copied from interface: Session
      Add one or more listeners to the Session
      Specified by:
      addEventListeners in interface Session
      Parameters:
      listeners - the listener(s) to add
    • createEntityGraph

      public <T> RootGraph<T> createEntityGraph(Class<T> rootType)
      Description copied from interface: SharedSessionContract
      Create a new mutable EntityGraph with only a root node.
      Specified by:
      createEntityGraph in interface EntityManager
      Specified by:
      createEntityGraph in interface Session
      Specified by:
      createEntityGraph in interface SharedSessionContract
      Parameters:
      rootType - the root entity class of the graph
      Returns:
      entity graph
    • createEntityGraph

      public RootGraph<?> createEntityGraph(String graphName)
      Description copied from interface: SharedSessionContract
      Create a new mutable copy of the named EntityGraph, or return null if there is no graph with the given name.
      Specified by:
      createEntityGraph in interface EntityManager
      Specified by:
      createEntityGraph in interface Session
      Specified by:
      createEntityGraph in interface SharedSessionContract
      Parameters:
      graphName - the name of the graph
      Returns:
      entity graph
      See Also:
    • createEntityGraph

      public <T> RootGraph<T> createEntityGraph(Class<T> rootType, String graphName)
      Description copied from interface: SharedSessionContract
      Create a new mutable copy of the named EntityGraph, or return null if there is no graph with the given name.
      Specified by:
      createEntityGraph in interface SharedSessionContract
      Parameters:
      rootType - the root entity class of the graph
      graphName - the name of the graph
      See Also:
    • getEntityGraph

      public RootGraph<?> getEntityGraph(String graphName)
      Description copied from interface: SharedSessionContract
      Retrieve the named EntityGraph as an immutable graph, or return null if there is no graph with the given name.
      Specified by:
      getEntityGraph in interface EntityManager
      Specified by:
      getEntityGraph in interface Session
      Specified by:
      getEntityGraph in interface SharedSessionContract
      Parameters:
      graphName - the name of the graph
      Returns:
      named entity graph
      See Also:
    • getEntityGraphs

      public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass)
      Description copied from interface: SharedSessionContract
      Retrieve all named EntityGraphs with the given type.
      Specified by:
      getEntityGraphs in interface EntityManager
      Specified by:
      getEntityGraphs in interface Session
      Specified by:
      getEntityGraphs in interface SharedSessionContract
      Parameters:
      entityClass - entity class
      Returns:
      list of all entity graphs defined for the entity
      See Also:
    • createQuery

      public <R> Query<R> createQuery(String queryString, Class<R> resultClass)
      Description copied from interface: QueryProducer
      Create a typed Query instance for the given HQL query string and given query result type.
      • If the query has a single item in the select list, 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, or Tuple.

      If a query has no explicit select list, 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 from clause, 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-fetch joined entity, and each query result will be packaged into an instance of the result type, just as specified above.

      The returned Query may be executed by calling Query.getResultList() or Query.getSingleResult().

      Specified by:
      createQuery in interface EntityManager
      Specified by:
      createQuery in interface QueryProducer
      Specified by:
      createQuery in interface Session
      Parameters:
      queryString - The HQL query
      resultClass - The type of the query result
      Returns:
      The Query instance for manipulation and execution
      See Also:
    • createQuery

      @Deprecated public Query createQuery(String queryString)
      Deprecated.
      Description copied from interface: QueryProducer
      Create a Query instance for the given HQL query, or HQL insert, update, or delete statement.

      If a query has no explicit select list, the select list is inferred:

      • if there is exactly one root entity in the from clause, then that root entity is the only element of the select list, or
      • otherwise, if there are multiple root entities in the from clause, then the select list contains every root entity and every non-fetch joined entity.
      Specified by:
      createQuery in interface EntityManager
      Specified by:
      createQuery in interface QueryProducer
      Specified by:
      createQuery in interface Session
      Parameters:
      queryString - The HQL query
      Returns:
      The Query instance for manipulation and execution
      See Also:
    • createNamedQuery

      public <R> Query<R> createNamedQuery(String name, Class<R> resultClass)
      Description copied from interface: QueryProducer
      Create a typed Query instance for the given named query. The named query might be defined in HQL or in native SQL.
      Specified by:
      createNamedQuery in interface EntityManager
      Specified by:
      createNamedQuery in interface QueryProducer
      Specified by:
      createNamedQuery in interface Session
      Parameters:
      name - the name of a query defined in metadata
      resultClass - the type of the query result
      Returns:
      The Query instance for manipulation and execution
      See Also:
    • createNamedQuery

      @Deprecated public Query createNamedQuery(String name)
      Deprecated.
      Description copied from interface: QueryProducer
      Create a typed Query instance for the given named query. The named query might be defined in HQL or in native SQL.
      Specified by:
      createNamedQuery in interface EntityManager
      Specified by:
      createNamedQuery in interface QueryProducer
      Specified by:
      createNamedQuery in interface Session
      Parameters:
      name - the name of a predefined named query
      Returns:
      The Query instance for manipulation and execution
      See Also:
    • createQuery

      public <R> Query<R> createQuery(CriteriaQuery<R> criteriaQuery)
      Description copied from interface: QueryProducer
      Create a Query for the given JPA CriteriaQuery.
      Specified by:
      createQuery in interface EntityManager
      Specified by:
      createQuery in interface QueryProducer
      Specified by:
      createQuery in interface Session
      Parameters:
      criteriaQuery - a criteria query object
      Returns:
      the new query instance
    • createQuery

      @Deprecated public Query createQuery(CriteriaDelete deleteQuery)
      Deprecated.
      Description copied from interface: Session
      Create a Query for the given JPA CriteriaDelete.
      Specified by:
      createQuery in interface EntityManager
      Specified by:
      createQuery in interface QueryProducer
      Specified by:
      createQuery in interface Session
      Parameters:
      deleteQuery - a criteria delete query object
      Returns:
      the new query instance
    • createQuery

      @Deprecated public Query createQuery(CriteriaUpdate updateQuery)
      Deprecated.
      Description copied from interface: Session
      Create a Query for the given JPA CriteriaUpdate.
      Specified by:
      createQuery in interface EntityManager
      Specified by:
      createQuery in interface QueryProducer
      Specified by:
      createQuery in interface Session
      Parameters:
      updateQuery - a criteria update query object
      Returns:
      the new query instance
    • getTenantIdentifier

      public String getTenantIdentifier()
      Description copied from interface: SharedSessionContract
      Obtain the tenant identifier associated with this session.
      Specified by:
      getTenantIdentifier in interface SharedSessionContract
      Returns:
      The tenant identifier associated with this session, or null
    • getTenantIdentifierValue

      public Object getTenantIdentifierValue()
      Description copied from interface: SharedSessionContract
      Obtain the tenant identifier associated with this session.
      Specified by:
      getTenantIdentifierValue in interface SharedSessionContract
      Returns:
      The tenant identifier associated with this session, or null
    • close

      public void close() throws HibernateException
      Description copied from interface: SharedSessionContract
      End the session by releasing the JDBC connection and cleaning up.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface EntityManager
      Specified by:
      close in interface SharedSessionContract
      Throws:
      HibernateException - Indicates problems cleaning up.
    • isOpen

      public boolean isOpen()
      Description copied from interface: SharedSessionContract
      Check if the session is still open.
      Specified by:
      isOpen in interface EntityManager
      Specified by:
      isOpen in interface SharedSessionContract
      Returns:
      boolean
    • isConnected

      public boolean isConnected()
      Description copied from interface: SharedSessionContract
      Check if the session is currently connected.
      Specified by:
      isConnected in interface SharedSessionContract
      Returns:
      boolean
    • beginTransaction

      public Transaction beginTransaction()
      Description copied from interface: SharedSessionContract
      Begin a unit of work and return the associated Transaction object. If a new underlying transaction is required, begin the transaction. Otherwise, continue the new work in the context of the existing underlying transaction.
      Specified by:
      beginTransaction in interface SharedSessionContract
      Returns:
      a Transaction instance
      See Also:
    • getTransaction

      public Transaction getTransaction()
      Description copied from interface: SharedSessionContract
      Get the Transaction instance associated with this session.
      Specified by:
      getTransaction in interface EntityManager
      Specified by:
      getTransaction in interface SharedSessionContract
      Returns:
      a Transaction instance
      See Also:
    • getNamedProcedureCall

      public ProcedureCall getNamedProcedureCall(String name)
      Description copied from interface: SharedSessionContract
      Obtain a ProcedureCall based on a named template
      Specified by:
      getNamedProcedureCall in interface SharedSessionContract
      Parameters:
      name - The name given to the template
      Returns:
      The ProcedureCall
      See Also:
    • createStoredProcedureCall

      public ProcedureCall createStoredProcedureCall(String procedureName)
      Description copied from interface: SharedSessionContract
      Create a ProcedureCall to a stored procedure.
      Specified by:
      createStoredProcedureCall in interface SharedSessionContract
      Parameters:
      procedureName - The name of the procedure.
      Returns:
      The representation of the procedure call.
    • createStoredProcedureCall

      public ProcedureCall createStoredProcedureCall(String procedureName, Class<?>... resultClasses)
      Description copied from interface: SharedSessionContract
      Create a ProcedureCall to a stored procedure with the given result set entity mappings. Each given class is considered a "root return".
      Specified by:
      createStoredProcedureCall in interface SharedSessionContract
      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

      public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings)
      Description copied from interface: SharedSessionContract
      Create a ProcedureCall to a stored procedure with the given result set entity mappings.
      Specified by:
      createStoredProcedureCall in interface SharedSessionContract
      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

      public ProcedureCall createNamedStoredProcedureQuery(String name)
      Description copied from interface: SharedSessionContract
      Obtain a ProcedureCall based on a named template
      Specified by:
      createNamedStoredProcedureQuery in interface EntityManager
      Specified by:
      createNamedStoredProcedureQuery in interface SharedSessionContract
      Parameters:
      name - The name given to the template
      Returns:
      The ProcedureCall
      See Also:
    • createStoredProcedureQuery

      public ProcedureCall createStoredProcedureQuery(String procedureName)
      Description copied from interface: SharedSessionContract
      Create a ProcedureCall to a stored procedure.
      Specified by:
      createStoredProcedureQuery in interface EntityManager
      Specified by:
      createStoredProcedureQuery in interface SharedSessionContract
      Parameters:
      procedureName - The name of the procedure.
      Returns:
      The representation of the procedure call.
    • createStoredProcedureQuery

      public ProcedureCall createStoredProcedureQuery(String procedureName, Class... resultClasses)
      Description copied from interface: SharedSessionContract
      Create a ProcedureCall to a stored procedure with the given result set entity mappings. Each given class is considered a "root return".
      Specified by:
      createStoredProcedureQuery in interface EntityManager
      Specified by:
      createStoredProcedureQuery in interface SharedSessionContract
      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

      public ProcedureCall createStoredProcedureQuery(String procedureName, String... resultSetMappings)
      Description copied from interface: SharedSessionContract
      Create a ProcedureCall to a stored procedure with the given result set entity mappings.
      Specified by:
      createStoredProcedureQuery in interface EntityManager
      Specified by:
      createStoredProcedureQuery in interface SharedSessionContract
      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

      public Integer getJdbcBatchSize()
      Description copied from interface: SharedSessionContract
      Get the session-level JDBC batch size for the current session.
      Specified by:
      getJdbcBatchSize in interface SharedSessionContract
      Returns:
      the current session-level JDBC batch size
      See Also:
    • setJdbcBatchSize

      public void setJdbcBatchSize(Integer jdbcBatchSize)
      Description copied from interface: SharedSessionContract
      Set the session-level JDBC batch size. Override the factory-level JDBC batch size controlled by the configuration property "hibernate.jdbc.batch_size".
      Specified by:
      setJdbcBatchSize in interface SharedSessionContract
      Parameters:
      jdbcBatchSize - the new session-level JDBC batch size
      See Also:
    • getFetchBatchSize

      public int getFetchBatchSize()
      Description copied from interface: Session
      Get the maximum batch size for batch fetching associations by id in this session.
      Specified by:
      getFetchBatchSize in interface Session
    • setFetchBatchSize

      public void setFetchBatchSize(int batchSize)
      Description copied from interface: Session
      Set 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:
      setFetchBatchSize in interface Session
      Parameters:
      batchSize - the maximum batch size for batch fetching
      See Also:
    • isSubselectFetchingEnabled

      public boolean isSubselectFetchingEnabled()
      Description copied from interface: Session
      Determine if subselect fetching is enabled in this session.
      Specified by:
      isSubselectFetchingEnabled in interface Session
      Returns:
      true is subselect fetching is enabled
    • setSubselectFetchingEnabled

      public void setSubselectFetchingEnabled(boolean enabled)
      Description copied from interface: Session
      Enable or disable subselect fetching in this session. Override the factory-level default controlled by the configuration property "hibernate.use_subselect_fetch".
      Specified by:
      setSubselectFetchingEnabled in interface Session
      Parameters:
      enabled - true to enable subselect fetching
      See Also:
    • getCriteriaBuilder

      public HibernateCriteriaBuilder getCriteriaBuilder()
      Description copied from interface: SharedSessionContract
      Obtain a HibernateCriteriaBuilder which may be used to construct criteria queries.
      Specified by:
      getCriteriaBuilder in interface EntityManager
      Specified by:
      getCriteriaBuilder in interface SharedSessionContract
      Returns:
      an instance of HibernateCriteriaBuilder
      See Also:
    • doWork

      public void doWork(Work work) throws HibernateException
      Description copied from interface: SharedSessionContract
      Perform work using the Connection underlying by this session.
      Specified by:
      doWork in interface SharedSessionContract
      Parameters:
      work - The work to be performed.
      Throws:
      HibernateException - Generally indicates wrapped SQLException
    • doReturningWork

      public <T> T doReturningWork(ReturningWork<T> work) throws HibernateException
      Description copied from interface: SharedSessionContract
      Perform work using the Connection underlying by this session, and return a result.
      Specified by:
      doReturningWork in interface SharedSessionContract
      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(java.sql.Connection).
      Throws:
      HibernateException - Generally indicates wrapped SQLException
    • createNativeQuery

      @Deprecated public NativeQuery createNativeQuery(String sqlString)
      Deprecated.
      Description copied from interface: QueryProducer
      Create a NativeQuery instance for the given native SQL query.
      Specified by:
      createNativeQuery in interface EntityManager
      Specified by:
      createNativeQuery in interface QueryProducer
      Parameters:
      sqlString - a native SQL query string
      Returns:
      The NativeQuery instance for manipulation and execution
      See Also:
    • createNativeQuery

      public NativeQuery createNativeQuery(String sqlString, Class resultClass)
      Description copied from interface: QueryProducer
      Create a NativeQuery instance 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 whose JdbcType is compatible with that JavaType.
      • 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, or Tuple.
      Specified by:
      createNativeQuery in interface EntityManager
      Specified by:
      createNativeQuery in interface QueryProducer
      Parameters:
      sqlString - The native (SQL) query string
      resultClass - The Java type to map results to
      Returns:
      The NativeQuery instance for manipulation and execution
      See Also:
    • createNativeQuery

      public <R> NativeQuery<R> createNativeQuery(String sqlString, Class<R> resultClass, String tableAlias)
      Description copied from interface: QueryProducer
      Create a NativeQuery instance 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:
      createNativeQuery in interface QueryProducer
      Parameters:
      sqlString - Native (SQL) query string
      resultClass - The Java entity class to map results to
      tableAlias - The table alias for columns in the result set
      Returns:
      The NativeQuery instance for manipulation and execution
      See Also:
    • createNativeQuery

      @Deprecated public NativeQuery createNativeQuery(String sqlString, String resultSetMappingName)
      Deprecated.
      Description copied from interface: QueryProducer
      Create a NativeQuery instance 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 SqlResultSetMapping annotation.

      Specified by:
      createNativeQuery in interface EntityManager
      Specified by:
      createNativeQuery in interface QueryProducer
      Parameters:
      sqlString - The native (SQL) query string
      resultSetMappingName - The explicit result mapping name
      Returns:
      The NativeQuery instance for manipulation and execution
      See Also:
    • createNativeQuery

      public <R> NativeQuery<R> createNativeQuery(String sqlString, String resultSetMappingName, Class<R> resultClass)
      Description copied from interface: QueryProducer
      Create a NativeQuery instance 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 SqlResultSetMapping annotation.

      Specified by:
      createNativeQuery in interface QueryProducer
      Parameters:
      sqlString - The native (SQL) query string
      resultSetMappingName - The explicit result mapping name
      Returns:
      The NativeQuery instance for manipulation and execution
      See Also:
    • createSelectionQuery

      public SelectionQuery<?> createSelectionQuery(String hqlString)
      Description copied from interface: QueryProducer
      Create a SelectionQuery reference for the given HQL select statement.

      If the statement has no explicit select list, the select list is inferred:

      • if there is exactly one root entity in the from clause, then that root entity is the only element of the select list, or
      • otherwise, if there are multiple root entities in the from clause, then the select list contains every root entity and every non-fetch joined entity.
      Specified by:
      createSelectionQuery in interface QueryProducer
    • createSelectionQuery

      public <R> SelectionQuery<R> createSelectionQuery(String hqlString, Class<R> resultType)
      Description copied from interface: QueryProducer
      Create a SelectionQuery instance for the given HQL query string and given query result type.
      • If the query has a single item in the select list, 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, or Tuple.

      If a query has no explicit select list, 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 from clause, 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-fetch joined entity, and each query result will be packaged into an instance of the result type, just as specified above.

      The returned Query may be executed by calling Query.getResultList() or Query.getSingleResult().

      Specified by:
      createSelectionQuery in interface QueryProducer
      Parameters:
      hqlString - The HQL query as a string
      resultType - The Class object representing the query result type
      See Also:
    • createSelectionQuery

      public <R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria)
      Description copied from interface: QueryProducer
      Create a SelectionQuery reference for the given CriteriaQuery.
      Specified by:
      createSelectionQuery in interface QueryProducer
      See Also:
    • createMutationQuery

      public MutationQuery createMutationQuery(String hqlString)
      Description copied from interface: QueryProducer
      Create a MutationQuery reference for the given HQL insert, update, or delete statement.
      Specified by:
      createMutationQuery in interface QueryProducer
    • createMutationQuery

      public MutationQuery createMutationQuery(CriteriaUpdate updateQuery)
      Description copied from interface: QueryProducer
      Create a MutationQuery from the given update criteria tree
      Specified by:
      createMutationQuery in interface QueryProducer
    • createMutationQuery

      public MutationQuery createMutationQuery(CriteriaDelete deleteQuery)
      Description copied from interface: QueryProducer
      Create a MutationQuery from the given delete criteria tree
      Specified by:
      createMutationQuery in interface QueryProducer
    • createMutationQuery

      public MutationQuery createMutationQuery(JpaCriteriaInsertSelect insertSelect)
      Description copied from interface: QueryProducer
      Create a MutationQuery from the given insert-select criteria tree
      Specified by:
      createMutationQuery in interface QueryProducer
    • createMutationQuery

      public MutationQuery createMutationQuery(JpaCriteriaInsert insertSelect)
      Description copied from interface: QueryProducer
      Create a MutationQuery from the given insert criteria tree
      Specified by:
      createMutationQuery in interface QueryProducer
    • createNativeMutationQuery

      public MutationQuery createNativeMutationQuery(String sqlString)
      Description copied from interface: QueryProducer
      Create a NativeQuery instance for the given native SQL statement.
      Specified by:
      createNativeMutationQuery in interface QueryProducer
      Parameters:
      sqlString - a native SQL statement string
      Returns:
      The NativeQuery instance for manipulation and execution
    • createNamedSelectionQuery

      public SelectionQuery<?> createNamedSelectionQuery(String name)
      Description copied from interface: QueryProducer
      Create a SelectionQuery instance for the named NamedQuery.
      Specified by:
      createNamedSelectionQuery in interface QueryProducer
    • createNamedSelectionQuery

      public <R> SelectionQuery<R> createNamedSelectionQuery(String name, Class<R> resultType)
      Description copied from interface: QueryProducer
      Create a SelectionQuery instance for the named NamedQuery with the given result type.
      Specified by:
      createNamedSelectionQuery in interface QueryProducer
    • createNamedMutationQuery

      public MutationQuery createNamedMutationQuery(String name)
      Description copied from interface: QueryProducer
      Create a MutationQuery instance for the given named insert, update, or delete HQL query. The named query might be defined as HQL) or native-SQL.
      Specified by:
      createNamedMutationQuery in interface QueryProducer
    • getNamedQuery

      @Deprecated public Query getNamedQuery(String queryName)
      Deprecated.
      Description copied from interface: QueryProducer
      Create a Query instance for the named query.
      Specified by:
      getNamedQuery in interface QueryProducer
      Parameters:
      queryName - the name of a predefined named query
      Returns:
      The Query instance for manipulation and execution
    • getNamedNativeQuery

      @Deprecated public NativeQuery getNamedNativeQuery(String name)
      Deprecated.
      Description copied from interface: QueryProducer
      Get a NativeQuery instance for a named native SQL query
      Specified by:
      getNamedNativeQuery in interface QueryProducer
      Parameters:
      name - The name of the predefined query
      Returns:
      The NativeQuery instance for manipulation and execution
    • getNamedNativeQuery

      @Deprecated public NativeQuery getNamedNativeQuery(String name, String resultSetMapping)
      Deprecated.
      Description copied from interface: QueryProducer
      Get a NativeQuery instance for a named native SQL query
      Specified by:
      getNamedNativeQuery in interface QueryProducer
      Parameters:
      name - The name of the predefined query
      Returns:
      The NativeQuery instance for manipulation and execution
    • find

      public <T> @Nullable T find(Class<T> entityClass, Object primaryKey)
      Description copied from interface: EntityManager
      Find by primary key. Search for an entity of the specified class and primary key. If the entity instance is contained in the persistence context, it is returned from there.
      Specified by:
      find in interface EntityManager
      Parameters:
      entityClass - entity class
      primaryKey - primary key
      Returns:
      the found entity instance or null if the entity does not exist
    • find

      public <T> @Nullable T find(Class<T> entityClass, Object primaryKey, Map<String,Object> properties)
      Description copied from interface: EntityManager
      Find by primary key, using the specified properties. Search for an entity of the specified class and primary key. If the entity instance is contained in the persistence context, it is returned from there. If a vendor-specific property or hint is not recognized, it is silently ignored.
      Specified by:
      find in interface EntityManager
      Parameters:
      entityClass - entity class
      primaryKey - primary key
      properties - standard and vendor-specific properties and hints
      Returns:
      the found entity instance or null if the entity does not exist
    • find

      public <T> @Nullable T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode)
      Description copied from interface: EntityManager
      Find by primary key and lock. Search for an entity of the specified class and primary key and lock it with respect to the specified lock type. If the entity instance is contained in the persistence context, it is returned from there, and the effect of this method is the same as if the lock method had been called on the entity.

      If the entity is found within the persistence context and the lock mode type is pessimistic and the entity has a version attribute, the persistence provider must perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException will be thrown.

      If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

      • the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback
      • the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback
      Specified by:
      find in interface EntityManager
      Parameters:
      entityClass - entity class
      primaryKey - primary key
      lockMode - lock mode
      Returns:
      the found entity instance or null if the entity does not exist
    • find

      public <T> @Nullable T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode, Map<String,Object> properties)
      Description copied from interface: EntityManager
      Find by primary key and lock, using the specified properties. Search for an entity of the specified class and primary key and lock it with respect to the specified lock type. If the entity instance is contained in the persistence context, it is returned from there.

      If the entity is found within the persistence context and the lock mode type is pessimistic and the entity has a version attribute, the persistence provider must perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException will be thrown.

      If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

      • the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback
      • the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback

      If a vendor-specific property or hint is not recognized, it is silently ignored.

      Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.

      Specified by:
      find in interface EntityManager
      Parameters:
      entityClass - entity class
      primaryKey - primary key
      lockMode - lock mode
      properties - standard and vendor-specific properties and hints
      Returns:
      the found entity instance or null if the entity does not exist
    • lock

      public void lock(Object entity, LockModeType lockMode)
      Description copied from interface: EntityManager
      Lock an entity instance that is contained in the persistence context with the specified lock mode type.

      If a pessimistic lock mode type is specified and the entity contains a version attribute, the persistence provider must also perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException will be thrown.

      If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

      • the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback
      • the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback
      Specified by:
      lock in interface EntityManager
      Parameters:
      entity - entity instance
      lockMode - lock mode
    • lock

      public void lock(Object entity, LockModeType lockMode, Map<String,Object> properties)
      Description copied from interface: EntityManager
      Lock an entity instance that is contained in the persistence context with the specified lock mode type and with specified properties.

      If a pessimistic lock mode type is specified and the entity contains a version attribute, the persistence provider must also perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException will be thrown.

      If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

      • the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback
      • the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback

      If a vendor-specific property or hint is not recognized, it is silently ignored.

      Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.

      Specified by:
      lock in interface EntityManager
      Parameters:
      entity - entity instance
      lockMode - lock mode
      properties - standard and vendor-specific properties and hints
    • refresh

      public void refresh(Object entity, Map<String,Object> properties)
      Description copied from interface: EntityManager
      Refresh the state of the instance from the database, using the specified properties, and overwriting changes made to the entity, if any.

      If a vendor-specific property or hint is not recognized, it is silently ignored.

      Specified by:
      refresh in interface EntityManager
      Parameters:
      entity - entity instance
      properties - standard and vendor-specific properties and hints
    • refresh

      public void refresh(Object entity, LockModeType lockMode)
      Description copied from interface: EntityManager
      Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type.

      If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

      • the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback
      • the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback.
      Specified by:
      refresh in interface EntityManager
      Parameters:
      entity - entity instance
      lockMode - lock mode
    • refresh

      public void refresh(Object entity, LockModeType lockMode, Map<String,Object> properties)
      Description copied from interface: EntityManager
      Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type and with specified properties.

      If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

      • the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback
      • the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback

      If a vendor-specific property or hint is not recognized, it is silently ignored.

      Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.

      Specified by:
      refresh in interface EntityManager
      Parameters:
      entity - entity instance
      lockMode - lock mode
      properties - standard and vendor-specific properties and hints
    • contains

      public boolean contains(Object entity)
      Description copied from interface: EntityManager
      Check if the instance is a managed entity instance belonging to the current persistence context.
      Specified by:
      contains in interface EntityManager
      Parameters:
      entity - entity instance
      Returns:
      boolean indicating if entity is in persistence context
    • getLockMode

      public LockModeType getLockMode(Object entity)
      Description copied from interface: EntityManager
      Get the current lock mode for the entity instance.
      Specified by:
      getLockMode in interface EntityManager
      Parameters:
      entity - entity instance
      Returns:
      lock mode
    • setProperty

      public void setProperty(String propertyName, Object value)
      Description copied from interface: EntityManager
      Set an entity manager property or hint. If a vendor-specific property or hint is not recognized, it is silently ignored.
      Specified by:
      setProperty in interface EntityManager
      Parameters:
      propertyName - name of property or hint
      value - value for property or hint
    • getProperties

      public Map<String,Object> getProperties()
      Description copied from interface: EntityManager
      Get the properties and hints and associated values that are in effect for the entity manager. Changing the contents of the map does not change the configuration in effect.
      Specified by:
      getProperties in interface EntityManager
      Returns:
      map of properties and hints in effect for entity manager
    • joinTransaction

      public void joinTransaction()
      Description copied from interface: SharedSessionContract
      Join the currently-active JTA transaction.
      Specified by:
      joinTransaction in interface EntityManager
      Specified by:
      joinTransaction in interface SharedSessionContract
      See Also:
    • isJoinedToTransaction

      public boolean isJoinedToTransaction()
      Description copied from interface: SharedSessionContract
      Check if the session is joined to the current transaction.
      Specified by:
      isJoinedToTransaction in interface EntityManager
      Specified by:
      isJoinedToTransaction in interface SharedSessionContract
      Returns:
      boolean
      See Also:
    • unwrap

      public <T> T unwrap(Class<T> cls)
      Description copied from interface: EntityManager
      Return an object of the specified type to allow access to the provider-specific API. If the provider's EntityManager implementation does not support the specified class, the PersistenceException is thrown.
      Specified by:
      unwrap in interface EntityManager
      Parameters:
      cls - the class of the object to be returned. This is normally either the underlying EntityManager implementation class or an interface that it implements.
      Returns:
      an instance of the specified class
    • getDelegate

      public Object getDelegate()
      Description copied from interface: EntityManager
      Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.

      The unwrap method is to be preferred for new applications.

      Specified by:
      getDelegate in interface EntityManager
      Returns:
      underlying provider object for EntityManager
    • getEntityManagerFactory

      public EntityManagerFactory getEntityManagerFactory()
      Description copied from interface: EntityManager
      Return the entity manager factory for the entity manager.
      Specified by:
      getEntityManagerFactory in interface EntityManager
      Returns:
      EntityManagerFactory instance
    • getMetamodel

      public Metamodel getMetamodel()
      Description copied from interface: EntityManager
      Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
      Specified by:
      getMetamodel in interface EntityManager
      Returns:
      Metamodel instance