persistence
persistence copied to clipboard
correct inaccuracies in JPA_SPEC 2.1 *7.6.4 Persistence Context Propagation*
Environment
Environment1: java7u80, wildfly 8.2.0.Final, wildfly-jpa-8.2.0.Final, hibernate 4.3.7.Final, weld 2.2.6.Final, wildfly-ejb3 8.2.0.Final, extended-persistence inheritance = DEEP(default)
Environment2: java8u77, wildfly 10.0.0.Final, wildfly-jpa-10.0.0.Final, hibernate 5.0.7.Final, weld 2.3.2.Final, wildfly-ejb3 10.0.0.Final, extended-persistence inheritance = DEEP(default)
Affected Versions
[2.2, 2.1.1]
- Issue Imported From: https://github.com/javaee/jpa-spec/issues/131
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @ldemichiel
@glassfishrobot Commented Reported by kostd
@glassfishrobot Commented kostd said: 1. 7.6.4.1 Requirements for Persistence Context Propagation
If an entity manager is then invoked from within the component: • Invocation of an entity manager defined with PersistenceContextType.TRANSACTION will result in use of a new persistence context (as described in section 7.6.2).
actually:
Invocation of an entity manager defined with PersistenceContextType.TRANSACTION will result in use of the existing persistence context, associated with current transaction, if one exists, or a new persistence context (as described in section 7.6.2).
2. 7.6.3 Container-managed Extended Persistence Context
A container-managed extended persistence context can only be initiated within the scope of a stateful session bean.
actually:
A container-managed extended persistence context can only be initiated within the scope of a stateful session bean or CDI non @Dependent bean. Dependent CDI beans cannot initiate extended persistence context, because no injected instance of one bean is ever shared between multiple injection points. Stateless beans cannot initiate extended persistence context because instance`s identity of beans not guaranteed.
@glassfishrobot Commented kostd said:
A container-managed extended persistence context can only be initiated within the scope of a stateful session bean or CDI non @Dependent bean
I lied
in fact CDI bean can initiate only transaction-scoped persistence context (hardcoded in weld implementation)
@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-131
This seems like low-hanging fruit that could be looked at in the next release and resolved one way or the other? It does appear to be a fairly low priority either way.
Reza Rahman Jakarta EE Ambassador, Author, Blogger, Speaker
Please note views expressed here are my own as an individual community member and do not reflect the views of my employer.
The first proposed change is not correct.
The context of that fragment of the spec is:
If a component is called and there is no JTA transaction or the JTA transaction is not propagated, the persistence context is not propagated.
If an entity manager is then invoked from within the component:
- Invocation of an entity manager defined with PersistenceContextType.TRANSACTION will result in use of a new persistence context (as described in <
>). ... - If the entity manager is invoked within a JTA transaction, the persistence context will be associated with the JTA transaction.
If a component is called and the JTA transaction is propagated into that component:
...
- Otherwise, if there is a persistence context associated with the JTA transaction, that persistence context is propagated and used.
All that looks correct to me.
I'm not sure I understand the implications of the second proposed change, but it seems to be a request for a new feature, not an "inaccuracy" in the spec.
I believe this should be closed.