-
1. Re: EnityManager.close() before or after JTA afterCompletion()?
tomjenkinson Feb 4, 2013 12:14 PM (in response to seyvet)Hi Seyvet,
I wouldn't want to comment on whether afterCompletion is the right place to call close for JPA, the thread you reference is probably the best place to discuss that. We are more concerned with raw transactions rather than resource manager or synchronization implementations in this forum.This is sort of a transaction manager in a nutshell:
Tx::enlistResource(RM rm)
Tsr::registerInterposedSynchronization(S s)
Tx::registerSynchronization(S s)
Tx::commit()
foreach Synchronization
s::beforeCompletion();
foreach InterposedSynchronization
s::beforeCompletion();
foreach ResourceManager
rm::prepare()
foreach ResourceManager
rm::commit()
foreach InterposedSynchronization
s::beforeCompletion();
foreach Synchronization
s::afterCompletion();
Is there a part of that algorithm that you would like to explore more with me in the context of JPA?
Tom
-
2. Re: EnityManager.close() before or after JTA afterCompletion()?
seyvet Feb 4, 2013 12:01 PM (in response to tomjenkinson)Thanks Tom,
Yes please!
The question is about the following sequence where after the transaction is committed:
1) The container will first invoke the JPA persistence provider as indicated by this first callback:
at org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:194)
at org.jboss.as.jpa.transaction.TransactionUtil$SessionSynchronization.afterCompletion(TransactionUtil.java:193)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:96)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:402)
2) Which is then followed by a second callback (JTA related this time) from the container:
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:96)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:402)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:103)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
The questions:
- Is this order defined by JBoss?
- Can this order be modified?
-
3. Re: EnityManager.close() before or after JTA afterCompletion()?
tomjenkinson Feb 4, 2013 12:13 PM (in response to seyvet)Hi Seyvet,
If you look at those two stack traces you can see a common line:
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:402)
The only ordering that can be guaranteed is for interposed synchronizations (registered by the TransactionSynchronizationRegistry):
There was a little mistype in my original response which I will now refactor in the original to say:
...
foreach ResourceManager
rm::commit()
foreach InterposedSynchronization
s::beforeCompletion();
foreach Synchronization
s::afterCompletion();
i.e. When it comes to afterCompletion, interposed synchronizations will be called *first* which is one way (if you only have two synchronizations ) to guarentee order.
-
4. Re: EnityManager.close() before or after JTA afterCompletion()?
seyvet Feb 4, 2013 12:23 PM (in response to tomjenkinson)In DataNucleus, the JTA transaction is registered as an interposed transaction, does that mean the JPA one is also interposed?
Should not that be specified in some spec?
-
5. Re: EnityManager.close() before or after JTA afterCompletion()?
tomjenkinson Feb 4, 2013 1:03 PM (in response to seyvet)Hi,
The ordering of interposed vs none-interposed is speced in JTA, in terms of whether JPA should be interposed or not I am not sure, perhaps it is?
Tom