Class ExtendedEntityManager

java.lang.Object
org.jboss.as.jpa.container.AbstractEntityManager
org.jboss.as.jpa.container.ExtendedEntityManager
All Implemented Interfaces:
jakarta.persistence.EntityManager, Serializable, AutoCloseable, SynchronizationTypeAccess

public class ExtendedEntityManager extends AbstractEntityManager implements Serializable, SynchronizationTypeAccess
Represents the Extended persistence context injected into a stateful bean. At bean invocation time, will join the active Jakarta Transactions transaction if one is present. If no active Jakarta Transactions transaction is present, created/deleted/updated/loaded entities will remain associated with the entity manager until it is joined with a transaction (commit will save the changes, rollback will lose them).

At injection time, an instance of this class is associated with the SFSB. During a SFSB1 invocation, if a new SFSB2 is created with an XPC referencing the same persistence unit, the new SFSB2 will inherit the same persistence context from SFSB1. Both SFSB1 + SFSB2 will maintain a reference to the underlying persistence context, such that the underlying persistence context will be kept around until both SFSB1 + SFSB2 are destroyed. At cluster replication time or passivation, both SFSB1 + SFSB2 will be serialized consecutively and this instance will only be serialized once.

Note: Unlike TransactionScopedEntityManager, ExtendedEntityManager will directly be shared instead of the underlying EntityManager.

During serialization, A NotSerializableException will be thrown if the following conditions are not met: - The underlying persistence provider (entity manager) must be Serializable. - The entity classes in the extended persistence context must also be Serializable.

Author:
Scott Marlow
See Also:
  • Constructor Details

    • ExtendedEntityManager

      public ExtendedEntityManager(String puScopedName, jakarta.persistence.EntityManager underlyingEntityManager, jakarta.persistence.SynchronizationType synchronizationType, jakarta.transaction.TransactionSynchronizationRegistry transactionSynchronizationRegistry, jakarta.transaction.TransactionManager transactionManager)
  • Method Details

    • getEntityManager

      protected jakarta.persistence.EntityManager getEntityManager()
      The Jakarta Persistence SFSB interceptor will track the stack of SFSB invocations. The underlying EM will be obtained from the current SFSB being invoked (via our Jakarta Persistence SFSB interceptor). Every entity manager call (to AbstractEntityManager) will call this method to get the underlying entity manager (e.g. the Hibernate persistence provider). See org.jboss.ejb3.stateful.EJB3XPCResolver.getExtendedPersistenceContext() to see the as6 implementation of this.
      Specified by:
      getEntityManager in class AbstractEntityManager
      Returns:
      EntityManager
    • internalAssociateWithJtaTx

      public void internalAssociateWithJtaTx()
      Associate the extended persistence context with the current Jakarta Transactions transaction (if one is found) this method is private to the Jakarta Persistence subsystem
    • isExtendedPersistenceContext

      protected boolean isExtendedPersistenceContext()
      Specified by:
      isExtendedPersistenceContext in class AbstractEntityManager
      Returns:
      true if an extended persistence context is in use

      Precondition: getEntityManager() must be called previous to calling isExtendedPersistenceContext

    • isInTx

      protected boolean isInTx()
      Specified by:
      isInTx in class AbstractEntityManager
      Returns:
      true if a Jakarta Transactions transaction active

      Precondition: getEntityManager() must be called previous to calling isInTx

    • close

      public void close()
      Catch the application trying to close the container managed entity manager and throw an IllegalStateException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface jakarta.persistence.EntityManager
      Overrides:
      close in class AbstractEntityManager
    • increaseReferenceCount

      public void increaseReferenceCount()
      Start of reference count handling. synchronize on *this* to protect access to the referenceCount (should be mostly uncontended locks).
    • getReferenceCount

      public int getReferenceCount()
    • refCountedClose

      public void refCountedClose()
    • toString

      public String toString()
      End of reference count handling
      Overrides:
      toString in class Object
    • getScopedPuName

      public String getScopedPuName()
      Get the fully application scoped persistence unit name Private api
      Returns:
      scoped pu name
    • equals

      public boolean equals(Object otherObject)
      Check if this object's UUID is equal to the otherObject's UUID
      Overrides:
      equals in class Object
      Parameters:
      otherObject -
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getSynchronizationType

      public jakarta.persistence.SynchronizationType getSynchronizationType()
      Specified by:
      getSynchronizationType in interface SynchronizationTypeAccess
      Specified by:
      getSynchronizationType in class AbstractEntityManager
    • deferEntityDetachUntilClose

      protected boolean deferEntityDetachUntilClose()
      Specified by:
      deferEntityDetachUntilClose in class AbstractEntityManager
    • skipQueryDetach

      protected boolean skipQueryDetach()
      Specified by:
      skipQueryDetach in class AbstractEntityManager