diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java index 0013a639f2..c88168f6aa 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java @@ -74,20 +74,30 @@ public class Caches { public static T withinTx( TransactionManager tm, Callable c) throws Exception { - tm.begin(); - try { - return c.call(); - } - catch (Exception e) { - tm.setRollbackOnly(); - throw e; - } - finally { - if ( tm.getStatus() == Status.STATUS_ACTIVE ) { - tm.commit(); + if ( tm == null ) { + try { + return c.call(); } - else { - tm.rollback(); + catch (Exception e) { + throw e; + } + } + else { + tm.begin(); + try { + return c.call(); + } + catch (Exception e) { + tm.setRollbackOnly(); + throw e; + } + finally { + if ( tm.getStatus() == Status.STATUS_ACTIVE ) { + tm.commit(); + } + else { + tm.rollback(); + } } } }