try {
TransactionManager tm = TransactionFactory.getTransactionManager();
if (tm != null && tm.getStatus() == STATUS_ACTIVE) {
Transaction tx = tm.getTransaction();
if (tx != null) {
tx.registerSynchronization(sync);
}
}
} catch (RollbackException e) {
//This is Java 1.4 only, but useful for certain debuggins: Throwable t = e.getCause() == null ? e : e.getCause();
throw new GenericTransactionException("Roll Back error, could not register synchronization in transaction even though transactions are available, current transaction rolled back", e);