Class EntityManagerImpl

  • All Implemented Interfaces:
    jakarta.persistence.EntityManager, AutoCloseable, JpaEntityManager

    public class EntityManagerImpl
    extends Object
    implements JpaEntityManager

    Purpose: Contains the implementation of the EntityManager.

    Description: This class provides the implementation for the combined EclipseLink and JPA EntityManager class.

    Responsibilities: It is responsible for tracking transaction state and the objects within that transaction.

    Since:
    TopLink Essentials - JPA 1.0
    Author:
    gyorke
    See Also:
    EntityManager, JpaEntityManager
    • Field Detail

      • isOpen

        protected boolean isOpen
        Store if this entity manager has been closed.
      • extendedPersistenceContext

        protected RepeatableWriteUnitOfWork extendedPersistenceContext
        Stores the UnitOfWork representing the persistence context.
      • readOnlySession

        protected AbstractSession readOnlySession
        Stores a session used for read-only queries.
      • databaseSession

        protected AbstractSession databaseSession
        References the DatabaseSession that this deployment is using.
      • factory

        protected EntityManagerFactoryDelegate factory
        References to the parent factory that has created this entity manager. Ensures that the factory is not garbage collected.
      • beginEarlyTransaction

        protected boolean beginEarlyTransaction
        Join existing transaction property, allows reading through write connection.
      • properties

        protected Map<String,​Object> properties
        Local properties passed from createEntityManager.
      • flushMode

        protected jakarta.persistence.FlushModeType flushMode
        Flush mode property, allows flush before query to be avoided.
      • referenceMode

        protected ReferenceMode referenceMode
        Reference mode property, allows weak unit of work references to allow garbage collection during a transaction.
      • connectionPolicy

        protected ConnectionPolicy connectionPolicy
        Connection policy used to create ClientSession, allows using a different pool/connection/exclusive connections. Not used in SessionBroker case (composite persistence unit case).
      • connectionPolicies

        protected Map<String,​ConnectionPolicy> connectionPolicies
        In case of composite persistence unit this map is used instead of connectionPolicy attribute. Member sessions' ConnectionPolicies keyed by sessions' names (composite members' persistence unit names). Used only in SessionBroker case (composite persistence unit case): in that case guaranteed to be always non null.
      • openQueriesMap

        protected WeakHashMap<QueryImpl,​QueryImpl> openQueriesMap
        Keep a list of openQueries that are executed in this entity manager.
      • closeOnCommit

        protected boolean closeOnCommit
        Property to avoid resuming unit of work if going to be closed on commit anyway.
      • persistOnCommit

        protected boolean persistOnCommit
        Property to avoid discover new objects in unit of work if application always uses persist.
      • cacheStoreBypass

        protected boolean cacheStoreBypass
        Property to avoid writing to the cache on commit (merge)
      • flushClearCache

        protected String flushClearCache
        The FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.
        See Also:
        FlushClearCache
      • shouldValidateExistence

        protected boolean shouldValidateExistence
        Determine if does-exist should be performed on persist.
      • commitWithoutPersistRules

        protected boolean commitWithoutPersistRules
      • syncType

        protected jakarta.persistence.SynchronizationType syncType
        Tracks if this EntityManager should automatically associate with the transaction or not
    • Constructor Detail

      • EntityManagerImpl

        public EntityManagerImpl​(String sessionName)
        Constructor returns an EntityManager assigned to the a particular DatabaseSession.
        Parameters:
        sessionName - the DatabaseSession name that should be used. This constructor can potentially throw EclipseLink exceptions regarding the existence, or errors with the specified session.
      • EntityManagerImpl

        public EntityManagerImpl​(AbstractSession databaseSession,
                                 jakarta.persistence.SynchronizationType syncType)
        Constructor called from the EntityManagerFactory to create an EntityManager
        Parameters:
        databaseSession - the databaseSession assigned to this deployment.
      • EntityManagerImpl

        public EntityManagerImpl​(AbstractSession databaseSession,
                                 Map properties,
                                 jakarta.persistence.SynchronizationType syncType)
        Constructor called from the EntityManagerFactory to create an EntityManager
        Parameters:
        databaseSession - the databaseSession assigned to this deployment. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented
      • EntityManagerImpl

        public EntityManagerImpl​(EntityManagerFactoryDelegate factory,
                                 Map properties,
                                 jakarta.persistence.SynchronizationType syncType)
        Constructor called from the EntityManagerFactory to create an EntityManager
        Parameters:
        factory - the EntityMangerFactoryImpl that created this entity manager. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented
    • Method Detail

      • getOpenQueriesMap

        protected Map<QueryImpl,​QueryImpl> getOpenQueriesMap()
        Return the weak reference to the open queries.
      • getOpenQueriesSet

        protected Set<QueryImpl> getOpenQueriesSet()
        Return the weak reference to the open queries.
      • addOpenQuery

        public void addOpenQuery​(QueryImpl query)
        Queries that leave the connection and are executed against this entity manager will be added here. On rollback or commit any left over open queries should be closed.
      • initialize

        protected void initialize​(Map properties)
        Initialize the state after construction.
      • clear

        public void clear()
        Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the database will not be persisted.
        Specified by:
        clear in interface jakarta.persistence.EntityManager
      • removeExtendedPersistenceContext

        public void removeExtendedPersistenceContext()
        Internal method called by EntityTransactionImpl class in case of transaction rollback. The caller is responsible for releasing extendedPersistenceContext and it's parent.
      • persist

        public void persist​(Object entity)
        If in a transaction this method will check for existence and register the object if it is new. The instance of the entity provided will become managed.
        Specified by:
        persist in interface jakarta.persistence.EntityManager
        Throws:
        IllegalArgumentException - if the given Object is not an entity.
      • merge

        public <T> T merge​(T entity)
        Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.
        Specified by:
        merge in interface jakarta.persistence.EntityManager
        Returns:
        the instance that the state was merged to
      • mergeInternal

        protected Object mergeInternal​(Object entity)
        Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.
        Returns:
        the instance that the state was merged to
        Throws:
        IllegalArgumentException - if given Object is not an entity or is a removed entity
      • remove

        public void remove​(Object entity)
        Remove the instance.
        Specified by:
        remove in interface jakarta.persistence.EntityManager
        Throws:
        IllegalArgumentException - if Object passed in is not an entity
      • find

        public <T> T find​(Class<T> entityClass,
                          Object primaryKey)
        Find by primary key.
        Specified by:
        find in interface jakarta.persistence.EntityManager
        Parameters:
        entityClass - - the entity class to find.
        primaryKey - - the entity primary key value, or primary key class, or a List of primary key values.
        Returns:
        the found entity instance or null if the entity does not exist
        Throws:
        IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key.
      • find

        public <T> T find​(Class<T> entityClass,
                          Object primaryKey,
                          Map<String,​Object> properties)
        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 jakarta.persistence.EntityManager
        Parameters:
        properties - standard and vendor-specific properties
        Returns:
        the found entity instance or null if the entity does not exist
        Throws:
        IllegalArgumentException - if the first argument does not denote an entity type or the second argument is is not a valid type for that entity's primary key or is null
        Since:
        Java Persistence API 2.0
      • find

        public <T> T find​(Class<T> entityClass,
                          Object primaryKey,
                          jakarta.persistence.LockModeType lockMode)
        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. 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 jakarta.persistence.EntityManager
        Returns:
        the found entity instance or null if the entity does not exist
        Throws:
        IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key or is null
        jakarta.persistence.TransactionRequiredException - if there is no transaction and a lock mode other than NONE is set
        jakarta.persistence.OptimisticLockException - if the optimistic version check fails
        jakarta.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        jakarta.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        jakarta.persistence.PersistenceException - if an unsupported lock call is made
      • find

        public <T> T find​(Class<T> entityClass,
                          Object primaryKey,
                          jakarta.persistence.LockModeType lockMode,
                          Map<String,​Object> properties)
        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. 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 jakarta.persistence.EntityManager
        Parameters:
        properties - standard and vendor-specific properties and hints
        Returns:
        the found entity instance or null if the entity does not exist
        Throws:
        IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key or is null
        jakarta.persistence.TransactionRequiredException - if there is no transaction and a lock mode other than NONE is set
        jakarta.persistence.OptimisticLockException - if the optimistic version check fails
        jakarta.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        jakarta.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        jakarta.persistence.PersistenceException - if an unsupported lock call is made
      • find

        public Object find​(String entityName,
                           Object primaryKey)
        Find by primary key.
        Parameters:
        entityName - - the entity class to find.
        primaryKey - - the entity primary key value, or primary key class, or a List of primary key values.
        Returns:
        the found entity instance or null, if the entity does not exist.
        Throws:
        IllegalArgumentException - if the first argument does not indicate an entity or if the second argument is not a valid type for that entity's primaryKey.
      • findInternal

        protected Object findInternal​(ClassDescriptor descriptor,
                                      AbstractSession session,
                                      Object id,
                                      jakarta.persistence.LockModeType lockMode,
                                      Map<String,​Object> properties)
        Find by primary key.
        Parameters:
        descriptor - - the entity class to find.
        id - - the entity primary key value, or primary key class, or a List of primary key values.
        Returns:
        the found entity instance or null, if the entity does not exist.
        Throws:
        IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key.
      • flush

        public void flush()
        Synchronize the persistence context with the underlying database.
        Specified by:
        flush in interface jakarta.persistence.EntityManager
      • detectTransactionWrapper

        protected void detectTransactionWrapper()
      • refresh

        public void refresh​(Object entity)
        Refresh the state of the instance from the database.
        Specified by:
        refresh in interface jakarta.persistence.EntityManager
        Parameters:
        entity - instance registered in the current persistence context.
      • refresh

        public void refresh​(Object entity,
                            Map<String,​Object> properties)
        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 jakarta.persistence.EntityManager
        Parameters:
        properties - standard and vendor-specific properties
        Throws:
        IllegalArgumentException - if the instance is not an entity or the entity is not managed
        jakarta.persistence.TransactionRequiredException - if invoked on a container-managed entity manager of type PersistenceContextType.TRANSACTION and there is no transaction.
        jakarta.persistence.EntityNotFoundException - if the entity no longer exists in the database
        Since:
        Java Persistence API 2.0
      • refresh

        public void refresh​(Object entity,
                            jakarta.persistence.LockModeType lockMode)
        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 jakarta.persistence.EntityManager
        Throws:
        IllegalArgumentException - if the instance is not an entity or the entity is not managed
        jakarta.persistence.TransactionRequiredException - if there is no transaction
        jakarta.persistence.EntityNotFoundException - if the entity no longer exists in the database
        jakarta.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        jakarta.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        jakarta.persistence.PersistenceException - if an unsupported lock call is made
      • refresh

        public void refresh​(Object entity,
                            jakarta.persistence.LockModeType lockMode,
                            Map<String,​Object> properties)
        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 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 jakarta.persistence.EntityManager
        Parameters:
        properties - standard and vendor-specific properties and hints
        Throws:
        IllegalArgumentException - if the instance is not an entity or the entity is not managed
        jakarta.persistence.TransactionRequiredException - if there is no transaction
        jakarta.persistence.EntityNotFoundException - if the entity no longer exists in the database
        jakarta.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        jakarta.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        jakarta.persistence.PersistenceException - if an unsupported lock call is made
      • contains

        public boolean contains​(Object entity)
        Check if the instance belongs to the current persistence context.
        Specified by:
        contains in interface jakarta.persistence.EntityManager
        Throws:
        IllegalArgumentException - if given Object is not an entity
      • contains

        protected boolean contains​(Object entity,
                                   UnitOfWork uow)
        Check if the instance belongs to the current persistence context.
      • createNamedQuery

        public jakarta.persistence.Query createNamedQuery​(String name)
        Create an instance of Query for executing a named query (in EJBQL or native SQL).
        Specified by:
        createNamedQuery in interface jakarta.persistence.EntityManager
        Parameters:
        name - the name of a query defined in metadata
        Returns:
        the new query instance
      • createNamedQuery

        public <T> jakarta.persistence.TypedQuery<T> createNamedQuery​(String name,
                                                                      Class<T> resultClass)
        Create an instance of TypedQuery for executing a named query (in the Java Persistence query language or in native SQL).
        Specified by:
        createNamedQuery in interface jakarta.persistence.EntityManager
        Parameters:
        name - the name of a query defined in metadata
        resultClass - the type of the query result
        Returns:
        the new query instance
        Throws:
        IllegalArgumentException - if a query has not been defined with the given name or if the query string is found to be invalid
      • createNamedStoredProcedureQuery

        public jakarta.persistence.StoredProcedureQuery createNamedStoredProcedureQuery​(String name)
        Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
        Specified by:
        createNamedStoredProcedureQuery in interface jakarta.persistence.EntityManager
        Parameters:
        name - name assigned to the stored procedure query in metadata
        Returns:
        the new stored procedure query instance
        Throws:
        IllegalArgumentException - if a query has not been defined with the given name
      • createNativeQuery

        public jakarta.persistence.Query createNativeQuery​(String sqlString)
        Create an instance of Query for executing a native SQL query.
        Specified by:
        createNativeQuery in interface jakarta.persistence.EntityManager
        Parameters:
        sqlString - a native SQL query string
        Returns:
        the new query instance
      • createNativeQuery

        public jakarta.persistence.Query createNativeQuery​(String sqlString,
                                                           Class resultType)
        This method is used to create a query using SQL. The class, must be the expected return type.
        Specified by:
        createNativeQuery in interface jakarta.persistence.EntityManager
      • createNativeQuery

        public jakarta.persistence.Query createNativeQuery​(String sqlString,
                                                           String resultSetMapping)
        Create an instance of Query for executing a native SQL query.
        Specified by:
        createNativeQuery in interface jakarta.persistence.EntityManager
        Parameters:
        sqlString - a native SQL query string
        resultSetMapping - the name of the result set mapping
        Returns:
        the new query instance
        Throws:
        IllegalArgumentException - if query string is not valid
      • getActiveSession

        public Session getActiveSession()
        This method returns the current session to the requestor. The current session will be a the active UnitOfWork within a transaction and will be a 'scrap' UnitOfWork outside of a transaction. The caller is concerned about the results then the getSession() or getUnitOfWork() API should be called.
        Specified by:
        getActiveSession in interface JpaEntityManager
      • getActiveSessionIfExists

        public AbstractSession getActiveSessionIfExists()
        This method returns the current session to the requestor. The current session will be a the active UnitOfWork within a transaction and will be a 'scrap' UnitOfWork outside of a transaction. The caller is concerned about the results then the getSession() or getUnitOfWork() API should be called.
      • getDelegate

        public Object getDelegate()
        Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.
        Specified by:
        getDelegate in interface jakarta.persistence.EntityManager
      • getFlushMode

        public jakarta.persistence.FlushModeType getFlushMode()
        Get the flush mode that applies to all objects contained in the persistence context.
        Specified by:
        getFlushMode in interface jakarta.persistence.EntityManager
        Returns:
        flushMode
      • getSession

        public Session getSession()
        This method will return a Session outside of a transaction and null within a transaction.
        Specified by:
        getSession in interface JpaEntityManager
      • getTransaction

        public jakarta.persistence.EntityTransaction getTransaction()
        Returns the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.
        Specified by:
        getTransaction in interface jakarta.persistence.EntityManager
        Returns:
        EntityTransaction instance
        Throws:
        IllegalStateException - if invoked on a JTA EntityManager.
      • getProperty

        public Object getProperty​(String name)
        The method search for user defined property passed in from EntityManager, if it is not found then search for it from EntityManagerFactory properties.
      • getReadObjectQuery

        protected ReadObjectQuery getReadObjectQuery​(Class<?> referenceClass,
                                                     Object primaryKey,
                                                     Map properties)
        Build a selection query for the primary key values.
      • getReadObjectQuery

        protected ReadObjectQuery getReadObjectQuery​(Map properties)
        Build a selection query using the given properties.
      • getReadObjectQuery

        protected ReadObjectQuery getReadObjectQuery​(Object entity,
                                                     Map properties)
        Build a selection query for the given entity.
      • getReference

        public <T> T getReference​(Class<T> entityClass,
                                  Object primaryKey)
        Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, throws EntityNotFoundException when the instance state is first accessed. (The container is permitted to throw EntityNotFoundException when get is called.) The application should not expect that the instance state will be available upon detachment, unless it was accessed by the application while the entity manager was open.
        Specified by:
        getReference in interface jakarta.persistence.EntityManager
        Returns:
        the found entity instance.
        Throws:
        IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key.
        jakarta.persistence.EntityNotFoundException - if the entity state cannot be accessed.
      • getReadOnlySession

        public Session getReadOnlySession()
        Return a read-only session (client session) for read-only operations.
      • setAbstractSession

        public void setAbstractSession​(AbstractSession session)
        INTERNAL: Set the underlying database session
      • getMemberDatabaseSession

        public DatabaseSessionImpl getMemberDatabaseSession​(Class<?> cls)
        Return the member DatabaseSessionImpl that maps cls in session broker. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.
        Specified by:
        getMemberDatabaseSession in interface JpaEntityManager
      • getMemberServerSession

        public ServerSession getMemberServerSession​(Class<?> cls)
        Return the member ServerSession that maps cls in session broker. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.
        Specified by:
        getMemberServerSession in interface JpaEntityManager
      • getMemberSessionName

        public String getMemberSessionName​(Class<?> cls)
        Return the name of member session that maps cls. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.
        Specified by:
        getMemberSessionName in interface JpaEntityManager
      • createQuery

        public jakarta.persistence.Query createQuery​(Expression expression,
                                                     Class<?> resultType)
        This method is used to create a query using a EclipseLink Expression and the return type.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public jakarta.persistence.Query createQuery​(DatabaseQuery databaseQuery)
        This method is used to create a query using a EclipseLink DatabaseQuery.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public <T> jakarta.persistence.TypedQuery<T> createQuery​(jakarta.persistence.criteria.CriteriaQuery<T> criteriaQuery)
        Specified by:
        createQuery in interface jakarta.persistence.EntityManager
        Since:
        Java Persistence 2.0
        See Also:
        EntityManager.createQuery(jakarta.persistence.criteria.CriteriaQuery)
      • createQueryByExample

        public jakarta.persistence.Query createQueryByExample​(Object exampleObject)
        This method is used to create a query using a EclipseLink by example.
        Specified by:
        createQueryByExample in interface JpaEntityManager
      • createQuery

        public jakarta.persistence.Query createQuery​(Call call)
        This method is used to create a query using a EclipseLink Call.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public jakarta.persistence.Query createQuery​(Call call,
                                                     Class<?> entityClass)
        This method is used to create a query using a EclipseLink Call.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public jakarta.persistence.Query createQuery​(String jpqlString)
        Create an instance of Query for executing an JPQL query.
        Specified by:
        createQuery in interface jakarta.persistence.EntityManager
        Parameters:
        jpqlString - an JPQL query string
        Returns:
        the new query instance
      • createQuery

        public <T> jakarta.persistence.TypedQuery<T> createQuery​(String qlString,
                                                                 Class<T> resultClass)
        Create an instance of TypedQuery for executing a Java Persistence query language statement.
        Specified by:
        createQuery in interface jakarta.persistence.EntityManager
        Parameters:
        qlString - a Java Persistence query string
        resultClass - the type of the query result
        Returns:
        the new query instance
        Throws:
        IllegalArgumentException - if the query string is found to be invalid
      • createQueryInternal

        protected DatabaseQuery createQueryInternal​(Expression expression,
                                                    Class<?> resultType)
        This method is used to create a query using a EclipseLink Expression and the return type.
      • createStoredProcedureQuery

        public jakarta.persistence.StoredProcedureQuery createStoredProcedureQuery​(String procedureName)
        Create an instance of StoredProcedureQuery for executing a stored procedure in the database.

        Parameters must be registered before the stored procedure can be executed.

        If the stored procedure returns one or more result sets, any result set will be returned as a list of type Object[].

        Specified by:
        createStoredProcedureQuery in interface jakarta.persistence.EntityManager
        Parameters:
        procedureName - name of the stored procedure in the database
        Returns:
        the new stored procedure query instance
        Throws:
        IllegalArgumentException - if a stored procedure of the given name does not exist (or the query execution will fail)
        Since:
        EclipseLink 2.5/Java Persistence 2.1
      • createStoredProcedureQuery

        public jakarta.persistence.StoredProcedureQuery createStoredProcedureQuery​(String procedureName,
                                                                                   Class... resultClasses)
        Create an instance of StoredProcedureQuery for executing a stored procedure in the database.

        Parameters must be registered before the stored procedure can be executed.

        The resultClass arguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.

        Specified by:
        createStoredProcedureQuery in interface jakarta.persistence.EntityManager
        Parameters:
        procedureName - name of the stored procedure in the database
        resultClasses - classes to which the result sets produced by the stored procedure are to be mapped
        Returns:
        the new stored procedure query instance
        Throws:
        IllegalArgumentException - if a stored procedure of the given name does not exist (or the query execution will fail)
        Since:
        EclipseLink 2.5/Java Persistence 2.1
      • createStoredProcedureQuery

        public jakarta.persistence.StoredProcedureQuery createStoredProcedureQuery​(String procedureName,
                                                                                   String... resultSetMappings)
        Create an instance of StoredProcedureQuery for executing a stored procedure in the database.

        Parameters must be registered before the stored procedure can be executed.

        The resultSetMapping arguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.

        Specified by:
        createStoredProcedureQuery in interface jakarta.persistence.EntityManager
        Parameters:
        procedureName - name of the stored procedure in the database
        resultSetMappings - the names of the result set mappings to be used in mapping result sets returned by the stored procedure
        Returns:
        the new stored procedure query instance
        Throws:
        IllegalArgumentException - if a stored procedure or result set mapping of the given name does not exist (or the query execution will fail)
        Since:
        EclipseLink 2.5/Java Persistence 2.1
      • close

        public void close()

        Closes this EntityManager.

        After invoking this method, all methods on the instance will throw an IllegalStateException except for isOpen, which will return false .

        This should be called when a method is finished with the EntityManager in a bean-managed transaction environment or when executed outside a container. Closing of the EntityManager is handled by the container when using container-managed transactions.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface jakarta.persistence.EntityManager
      • closeOpenQueries

        protected void closeOpenQueries()
        Close any open queries executed against this entity manager.0
      • isFlushModeAUTO

        public boolean isFlushModeAUTO()
        Internal method. Indicates whether flushMode is AUTO.
        Returns:
        boolean
      • isOpen

        public boolean isOpen()
        Indicates whether or not this entity manager and its entity manager factory are open. Returns true until a call to close() is made.
        Specified by:
        isOpen in interface jakarta.persistence.EntityManager
      • lock

        public void lock​(Object entity,
                         jakarta.persistence.LockModeType lockMode)
        Set the lock mode for an entity object contained in the persistence context.
        Specified by:
        lock in interface jakarta.persistence.EntityManager
        Throws:
        jakarta.persistence.PersistenceException - if an unsupported lock call is made
        IllegalArgumentException - if the instance is not an entity or is a detached entity
        jakarta.persistence.TransactionRequiredException - if there is no transaction
      • lock

        public void lock​(Object entity,
                         jakarta.persistence.LockModeType lockMode,
                         Map<String,​Object> properties)
        Set the lock mode for an entity object contained in the persistence context.
        Specified by:
        lock in interface jakarta.persistence.EntityManager
        Throws:
        jakarta.persistence.PersistenceException - if an unsupported lock call is made
        IllegalArgumentException - if the instance is not an entity or is a detached entity
        jakarta.persistence.TransactionRequiredException - if there is no transaction
      • verifyOpen

        public void verifyOpen()
      • verifyOpenWithSetRollbackOnly

        public void verifyOpenWithSetRollbackOnly()
        used to save having to constantly use a try/catch to call setRollbackOnly
      • setProperties

        public void setProperties​(Map properties)
        Use this method to set properties into existing EntityManager that are normally passed to createEntityManager method. Note that if the method called when active persistence context already exists then properties used to create persistence context will be ignored until the new persistence context is created (that happens either after transaction rolled back or after clear method was called).
      • setProperty

        public void setProperty​(String propertyName,
                                Object value)
        Specified by:
        setProperty in interface jakarta.persistence.EntityManager
        See Also:
        EntityManager.setProperty(java.lang.String, java.lang.Object)
      • hasActivePersistenceContext

        public boolean hasActivePersistenceContext()
        This method is used in contains to check if we already have a persistence context. If there is no active persistence context the method returns false
      • checkForTransaction

        protected Object checkForTransaction​(boolean validateExistence)
        Return the current, joined transaction object. If validateExistence is true throw an error if there is no joined transaction, otherwise return null.
      • shouldFlushBeforeQuery

        public boolean shouldFlushBeforeQuery()
      • shouldBeginEarlyTransaction

        public boolean shouldBeginEarlyTransaction()
        Indicate the early transaction should be forced to start. This allows for reading through the write connection. As a side effect, this will also prevent anything from being cached.
      • joinTransaction

        public void joinTransaction()
        Indicate to the EntityManager that a JTA transaction is active. This method should be called on a JTA application managed EntityManager that was created outside the scope of the active transaction to associate it with the current JTA transaction.
        Specified by:
        joinTransaction in interface jakarta.persistence.EntityManager
        Throws:
        jakarta.persistence.TransactionRequiredException - if there is no transaction.
      • setRollbackOnly

        protected void setRollbackOnly()
        Internal method. Sets transaction to rollback only.
      • processProperties

        protected void processProperties()
        Process the local EntityManager properties only. The persistence unit properties are processed by the factory.
      • getPropertiesHandlerProperty

        protected String getPropertiesHandlerProperty​(String name)
        Get the local EntityManager property from the properties Map. This only searches the local Map. The persistence unit properties are processed by the EntityManagerFactory.
      • getPropertiesHandlerProperty

        protected static String getPropertiesHandlerProperty​(String name,
                                                             String value)
        Verifies and (if required) translates the value.
      • setEntityTransactionWrapper

        protected void setEntityTransactionWrapper()
      • setFlushMode

        public void setFlushMode​(jakarta.persistence.FlushModeType flushMode)
        Set the flush mode that applies to all objects contained in the persistence context.
        Specified by:
        setFlushMode in interface jakarta.persistence.EntityManager
      • setJTATransactionWrapper

        protected void setJTATransactionWrapper()
      • createConnectionPolicy

        protected void createConnectionPolicy()
        Create connection policy using properties. Default connection policy created if no connection properties specified. Should be called only in case this.databaseSession is a ServerSession.
      • createConnectionPolicies

        protected void createConnectionPolicies​(Map mapOfProperties)
        Create connection policy using properties. Default connection policy created if no connection properties specified. Should be called only in case this.databaseSession is a SessionBroker.
      • createConnectionPolicy

        protected static ConnectionPolicy createConnectionPolicy​(ServerSession serverSession,
                                                                 Map properties)
        Create connection policy using properties. Default connection policy created if no connection properties specified.
      • isBroker

        public boolean isBroker()
        Indicates whether the underlying session is a session broker. Session broker implement composite persistence unit.
        Specified by:
        isBroker in interface JpaEntityManager
      • isPropertyToBeAdded

        protected static boolean isPropertyToBeAdded​(String value)
        Property value is to be added if it's non null and not an empty string.
      • isPropertyToBeAdded

        protected static boolean isPropertyToBeAdded​(DataSource ds,
                                                     String dsName)
      • isPropertyToBeRemoved

        protected static boolean isPropertyToBeRemoved​(String value)
        Property value of an empty string indicates that the existing property should be removed.
      • isPropertyValueToBeUpdated

        protected static Boolean isPropertyValueToBeUpdated​(String oldValue,
                                                            String newValue)
        Returns:
        null: no change; TRUE: substitute oldValue by newValue; FALSE: remove oldValue
      • detach

        public void detach​(Object entity)
        Remove the given entity from the persistence context, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it.
        Specified by:
        detach in interface jakarta.persistence.EntityManager
        Throws:
        IllegalArgumentException - if the instance is not an entity
        Since:
        Java Persistence 2.0
      • getCriteriaBuilder

        public jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
        Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.
        Specified by:
        getCriteriaBuilder in interface jakarta.persistence.EntityManager
        Returns:
        CriteriaBuilder instance
        Throws:
        IllegalStateException - if the entity manager has been closed.
        Since:
        Java Persistence 2.0
        See Also:
        EntityManager.getCriteriaBuilder()
      • getMetamodel

        public jakarta.persistence.metamodel.Metamodel getMetamodel()
        Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
        Specified by:
        getMetamodel in interface jakarta.persistence.EntityManager
        Returns:
        Metamodel instance
        Throws:
        IllegalStateException - if the entity manager has been closed.
        Since:
        Java Persistence 2.0
        See Also:
        EntityManager.getMetamodel()
      • getEntityManagerFactory

        public jakarta.persistence.EntityManagerFactory getEntityManagerFactory()
        Return the entity manager factory for the entity manager.
        Specified by:
        getEntityManagerFactory in interface jakarta.persistence.EntityManager
        Returns:
        EntityManagerFactory instance
        Throws:
        IllegalStateException - if the entity manager has been closed.
        Since:
        Java Persistence API 2.0
      • getLockMode

        public jakarta.persistence.LockModeType getLockMode​(Object entity)
        Specified by:
        getLockMode in interface jakarta.persistence.EntityManager
        Since:
        Java Persistence API 2.0
        See Also:
        EntityManager.getLockMode(java.lang.Object)
      • getProperties

        public Map<String,​Object> getProperties()
        Get the properties 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 jakarta.persistence.EntityManager
        Since:
        Java Persistence API 2.0
      • getSupportedProperties

        public Set<String> getSupportedProperties()
        Get the names of the properties that are supported for use with the entity manager. These correspond to properties and hints that may be passed to the methods of the EntityManager interface that take a properties argument or used with the PersistenceContext annotation. These properties include all standard entity manager hints and properties as well as vendor-specific ones supported by the provider. These properties may or may not currently be in effect.
        Returns:
        property names
        Since:
        Java Persistence API 2.0
      • unwrap

        public <T> T unwrap​(Class<T> cls)
        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 jakarta.persistence.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
        Throws:
        jakarta.persistence.PersistenceException - if the provider does not support the call.
        Since:
        Java Persistence API 2.0
      • load

        public void load​(Object entityOrEntities,
                         AttributeGroup group)
        This method will load the passed entity or collection of entities using the passed AttributeGroup. In case of collection all members should be either entities of the same type or have a common inheritance hierarchy mapped root class. The AttributeGroup should correspond to the entity type.
        Specified by:
        load in interface JpaEntityManager
      • copy

        public Object copy​(Object entityOrEntities,
                           AttributeGroup group)
        This method will return copy the passed entity using the passed AttributeGroup. In case of collection all members should be either entities of the same type or have a common inheritance hierarchy mapped root class. The AttributeGroup should correspond to the entity type.
        Specified by:
        copy in interface JpaEntityManager
      • processUnfetchedAttribute

        public static void processUnfetchedAttribute​(FetchGroupTracker entity,
                                                     String attributeName)
        INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWaver..
      • processUnfetchedAttributeForSet

        public static void processUnfetchedAttributeForSet​(FetchGroupTracker entity,
                                                           String attributeName)
        INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWeaver.
      • createQuery

        public jakarta.persistence.Query createQuery​(jakarta.persistence.criteria.CriteriaUpdate updateQuery)
        Specified by:
        createQuery in interface jakarta.persistence.EntityManager
      • createQuery

        public jakarta.persistence.Query createQuery​(jakarta.persistence.criteria.CriteriaDelete deleteQuery)
        Specified by:
        createQuery in interface jakarta.persistence.EntityManager
      • isJoinedToTransaction

        public boolean isJoinedToTransaction()
        Specified by:
        isJoinedToTransaction in interface jakarta.persistence.EntityManager
      • createEntityGraph

        public <T> jakarta.persistence.EntityGraph<T> createEntityGraph​(Class<T> rootType)
        Specified by:
        createEntityGraph in interface jakarta.persistence.EntityManager
      • createEntityGraph

        public jakarta.persistence.EntityGraph createEntityGraph​(String graphName)
        Specified by:
        createEntityGraph in interface jakarta.persistence.EntityManager
      • getEntityGraph

        public jakarta.persistence.EntityGraph getEntityGraph​(String graphName)
        Specified by:
        getEntityGraph in interface jakarta.persistence.EntityManager
      • getEntityGraphs

        public <T> List<jakarta.persistence.EntityGraph<? super T>> getEntityGraphs​(Class<T> entityClass)
        Specified by:
        getEntityGraphs in interface jakarta.persistence.EntityManager
      • getSyncType

        public jakarta.persistence.SynchronizationType getSyncType()
        INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or not
        Returns:
        the syncType