persistence icon indicating copy to clipboard operation
persistence copied to clipboard

correct inaccuracies in JPA_SPEC 2.1 *7.6.4 Persistence Context Propagation*

Open lukasj opened this issue 9 years ago • 6 comments
trafficstars

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]

lukasj avatar Jul 06 '16 11:07 lukasj

  • Issue Imported From: https://github.com/javaee/jpa-spec/issues/131
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @ldemichiel

lukasj avatar Aug 31 '18 16:08 lukasj

@glassfishrobot Commented Reported by kostd

lukasj avatar Jul 06 '16 11:07 lukasj

@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.

lukasj avatar Jul 06 '16 12:07 lukasj

@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)

lukasj avatar Aug 31 '16 18:08 lukasj

@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-131

lukasj avatar May 05 '17 06:05 lukasj

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.

m-reza-rahman avatar May 06 '21 21:05 m-reza-rahman

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.

gavinking avatar Aug 15 '23 19:08 gavinking