Transaction is being rollbacked successfully as reflected by the code.However the operation which are performed in transaction were not reflected to the database and were not rolledback in non-committed active state of tx i.e. when records are deleled using tx(Transaction) of PMF and DynaPMF rollback for undo the operation does not works.
Here PMF, DynaPMF refer to 2 distinct PersistanceMangerFactory for two different database
if (isTransactionLocal || (PMF.getTransactionCounter() > 0 || DynaPMF.getTransactionCounter() > 0)) {
//tx.rollback();
if(PMF.getPerThreadTransaction()!=null){
tx=PMF.getPerThreadTransaction();
System.err.println(tx.hashCode()+"transaction thread is Alive =>"+tx.isActive());
if(tx.isActive()){
tx.rollback();
System.err.println("rollback for tx = "+tx.hashCode()+" done .");
}
}
if(DynaPMF.getPerThreadTransaction()!=null){
tx=DynaPMF.getPerThreadTransaction();
System.err.println(tx.hashCode()+"transaction thread is Alive =>"+tx.isActive());
if(tx.isActive()){
tx.rollback();
System.err.println("rollback for tx = "+tx.hashCode()+" done .");
}
}
PMF.setPerThreadTransaction(null);
DynaPMF.setPerThreadTransaction(null);
Output:
1861140113transaction thread is Alive =>true
rollback for tx = 1861140113 done .
336180090transaction thread is Alive =>true
rollback for tx = 336180090 done .
It is showing in code that rollback occurred successfully, but not reflecting in database.
As per JDO rollback can be performed only on those objects which have persistance-clean state during JDO Lifecycle as can be seen from https://db.apache.org/jdo/state_transition.html and rollback from other state cannot be reflected to datastore.