-
15. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
smarlow Jan 28, 2013 12:21 PM (in response to seyvet)No ordering is promised by the jta specification other than each synchronization registered with the transaction synchronization registry will be invoked after the transaction completes (before the Transaction registered callbacks are invoked).
If the EntityManager was still open, what would DataNucleus do with it in its afterCompletion callback?
-
16. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
seyvet Jan 28, 2013 12:49 PM (in response to smarlow)To be clear, afterCompletion() is invoked by JTA as part of the import javax.transaction.Synchronization implementation.
In the afterCompletion, the Tx is released:
- the transaction listeners are invoked with transactionCommitted().
- listeners are cleared.
- Then there is this line that I do not understand:
// call sync.afterCompletion() only now to support the use-case of closing the PM in afterCompletion()
if (sync != null)
{
sync.afterCompletion(Status.STATUS_COMMITTED);
}
- jtaTx ref is set to null;
- joinStatus = JoinStatus.NO_TXN;
See JTATransactionImpl,java (https://datanucleus.svn.sourceforge.net/svnroot/datanucleus/platform/core/trunk/src/java/org/datanucleus/JTATransactionImpl.java), TransactionImpl.java
-
17. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
smarlow Jan 29, 2013 11:38 AM (in response to seyvet)I think that the part about closing the PM (persistence manager) is invoking the EntityManager.close() method that the EE container is responsible for handling.
-
18. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
smarlow Feb 1, 2013 11:29 AM (in response to smarlow)Also, we previously said that the transaction is active in the after completion. That is not true as pointed out earlier (I later said it wasn't wrong for the tx to be active in afterCompletion and I was wrong about that):
I have debugged a but further and this is the Arjuna Tx state on the afterCompletion() -> Close(), in the ExecutionContextImpl:
jtaTx = {com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple@2281} "TransactionImple < ac, BasicAction: 0:ffffc0a83801:-191825a3:50fa7887:19 status: ActionStatus.COMMITTED >"
joinStatus = {org.datanucleus.JTATranasactionImpl$JoinStatus@2308} "JOINED"
Since that part is now clearer, I think that we just need someone to contribute a patch to DataNucleuos to stop trying to close the EntityManager in the afterCompletion, since the EE container will do that or the application will for non-EE. In addition to the DataNucleus forum discussion, have you created a bug report as well?
Scott
-
19. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
seyvet Feb 1, 2013 12:25 PM (in response to smarlow)Hi Scott, the DN issue can be found here: http://www.datanucleus.org/servlet/jira/browse/NUCCORE-985
As indicated by remote debugging:
1) Based on the thread dump, arjuna calls first in the afterCompletion method in TransactionUtil, then EntityManager.close():
{code}
at org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:194)
at org.jboss.as.jpa.transaction.TransactionUtil$SessionSynchronization.afterCompletion(TransactionUtil.java:193)
{code}
=>The above means that JBoss calls EntityManager.close() first.
2) Then arjuna calls the afterCompletion method of the javax.jta.Synchronization class:
{code}
at org.datanucleus.TransactionImpl.internalPostCommit(TransactionImpl.java:563)
at org.datanucleus.JTATransactionImpl.afterCompletion(JTATransactionImpl.java:429)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:96)
{code}
=> The above means that JBoss calls Synchronization.afterCompletion() second.
In short, JBoss invokes first EntityManager.close() and then Synchronization.afterCompletion().
The problem for DN is the order. DN expects the Synchronization afterCompletion() method to be called first in order to flag the Transaction marker in DN as inactive. This flag is then re-used in the EntityManager to detect if the Transaction is active.
Andy made some changes to accomodate DB and JBoss but all in all we are not sure what is the proper order of invocation, and no one in the
https://community.jboss.org/community/jbosstm/dev has commented on this.
-
20. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
smarlow Feb 1, 2013 1:46 PM (in response to seyvet)Andy made some changes to accomodate DB and JBoss but all in all we are not sure what is the proper order of invocation, and no one in the
https://community.jboss.org/community/jbosstm/dev has commented on this.
DataNucleus is currently closing the entity manager, when the JPA specification clearly states in section 7.9.1, that the (EE) container is responsible for doing that.
I looked at the jbosstm/dev posting and you might want to focus on the pure JTA part of the questions that you post there about ordering of interposed/non-interposed synchronization callbacks. Although, it doesn't matter that much since the DN synchronization callback shouldn't try to close the entity manager when that is an (ee) container responsibility.
-
21. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
seyvet Feb 1, 2013 2:52 PM (in response to smarlow)Scott Marlow wrote:
DataNucleus is currently closing the entity manager, when the JPA specification clearly states in section 7.9.1, that the (EE) container is responsible for doing that.
What makes you say this? Do you mean that this is not the container callback that is invoking the entity manager close() but that DN has registered twice to the JTA?
Again, the first trace:
at org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:194)
at org.jboss.as.jpa.transaction.TransactionUtil$SessionSynchronization.afterCompletion(TransactionUtil.java:193)Clearly indicates that Jpa is calling in entity manager close()
And THEN jta calls after check the package names:
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:96)
Scott Marlow wrote:
I looked at the jbosstm/dev posting and you might want to focus on the pure JTA part of the questions that you post there about ordering of interposed/non-interposed synchronization callbacks.
I will try to clarify my post.
-
22. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
smarlow Feb 1, 2013 4:39 PM (in response to seyvet)seyvet wrote:
Scott Marlow wrote:
DataNucleus is currently closing the entity manager, when the JPA specification clearly states in section 7.9.1, that the (EE) container is responsible for doing that.
What makes you say this? Do you mean that this is not the container callback that is invoking the entity manager close() but that DN has registered twice to the JTA?
Your right, I was wrong to say ^. I posted again to the NUCCORE-985 jira (updating that I was wrong about DN also closing the EM) and Andy seems to be responding on there are well.
Would you be interested in creating a wiki page about using DataNucleus + AS7? It could be similar to https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7
Scott
-
23. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
seyvet Feb 2, 2013 5:09 AM (in response to smarlow)Scott Marlow wrote:
Would you be interested in creating a wiki page about using DataNucleus + AS7? It could be similar to https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7
Scott
There is one on the DN wiki: http://www.datanucleus.org/servlet/wiki/pages/viewpage.action?pageId=27688962. But I can also add one to the JBoss community site, or would the cross-links be enough?
-
24. Re: Synchronization failure on aftrCompletion when using DataNucleus 3.2
smarlow Feb 2, 2013 10:01 PM (in response to seyvet)The guide looks great, I added a cross link here.