Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jpa-dev] Jakarta Persistence container responsibilities and impact on management of a transaction-scoped persistence context...

Hi,

We were discussing [1] what it means for an EE/Persistence container to (CDI) inject a container-managed entity manager and why EE/Persistence containers need to use the rules described in [2] when injecting a Container-managed entity manager. Or do they really?

I wanted to start this thread to explain in more detail why I believe the answer is currently important on Jakarta EE 10 and earlier EE releases for Jakarta EE/Persistence containers to follow the rules in [2] and that being to ensure that applications can depend on the [2][3][4] rules for how Persistence works in all Jakarta EE 10 (and earlier) implementations.  It is true that part of the rules for containers are specifically for EJB but they apply to more than EJBs.  

For example, the first container rule described in [2] states:
"
The container creates a new entity manager by calling EntityManagerFactory.createEntityManager when the first invocation of an entity manager with PersistenceContextType.TRANSACTION occurs within the scope of a business method executing in the JTA transaction.
"

While the above rule applies to EJBs, it also applies to other components as well.  It is not a difficult rule to implement but still it is the responsibility of the EE/Persistence container to perform.  If an EE implementation does not do this then the application would have to call joinTransaction() but shouldn't have to.  The persistence provider in use might also call joinTransaction but also shouldn't have to since the container is required to have done that already.

A separate raised concern to discuss is whether the [2][3][4] rules should still apply when using the new CDI/Persistence integration feature proposed by [1]?  

Scott

[1] define how a container should provide native integration of CDI with JPA https://github.com/jakartaee/persistence/pull/460#issuecomment-1789299760
[2] Container Responsibilities https://jakarta.ee/specifications/persistence/3.1/jakarta-persistence-spec-3.1#container-responsibilities
[3]  Container-managed Persistence Contexts https://jakarta.ee/specifications/persistence/3.1/jakarta-persistence-spec-3.1#a11791 
[4] Jakarta EE Deployment https://jakarta.ee/specifications/persistence/3.1/jakarta-persistence-spec-3.1#a12802
[5] https://jakarta.ee/specifications/persistence/3.1/apidocs/jakarta.persistence/jakarta/persistence/spi/persistenceprovider#createContainerEntityManagerFactory(jakarta.persistence.spi.PersistenceUnitInfo,java.util.Map)
[6] https://jakarta.ee/specifications/persistence/3.1/apidocs/jakarta.persistence/jakarta/persistence/spi/persistenceprovider#createEntityManagerFactory(java.lang.String,java.util.Map)

Back to the top