AnsweredAssumed Answered

Why commit in transaction don't do this until the webscript is finished?

Question asked by spilby on Jul 11, 2014
Latest reply on Jul 23, 2014 by spilby
I'm implementing a java backed webscript. In my description doc the transaction is specified like required.


<transaction>required</transaction>


I have something like this:


UserTransaction trx = serviceRegistry.getTransactionService().getUserTransaction(false);
try {
   trx.begin();
   Alfresco OPERATION 1
   Alfresco OPERATION 2
   trx.commit();
} catch(Throwable e) {
   trx.rollback();
   …
}


And after, in other part of the code, I have something like this:


UserTransaction trx = serviceRegistry.getTransactionService().getUserTransaction(false);
try {
   trx.begin();
   Alfresco OPERATION 3
   Alfresco OPERATION 4
   trx.commit();
} catch(Throwable e) {
   trx.rollback();
   …
}


If the OPERATION 4 not works, I want to have a rollback only of the operations 3 and 4. And the operation 1 and 2 commit ok. Is the reason I have different transactions.

But the webscript don't do this. When the operation 4 fails (I induce a exception there to test it), the webscript do the rollback of all: 1, 2, 3 and 4. I don't understand why, if I do the commit after operation 2.

This trx.commit is parcial? The real commit is doing when the webscript ends? Somebody knows the reason, please?

Thanks a lot!



Outcomes