try {
log.debug("rolling back hibernate transaction");
mustSessionBeFlushed = false; // flushing updates that will be rolled back is not very clever :-)
transaction.rollback();
} catch (Throwable t) {
throw new JbpmPersistenceException("couldn't rollback hibernate session", t);
}
} else {
try {
log.debug("committing hibernate transaction");
mustSessionBeFlushed = false; // commit does a flush anyway
transaction.commit();
} catch (Throwable t) {
try {
// if the commit fails, we must do a rollback
transaction.rollback();
} catch (Throwable t2) {
// if the rollback fails, we did what we could and you're in
// deep shit :-(
log.error("problem rolling back after failed commit", t2);
}
throw new JbpmPersistenceException("couldn't commit hibernate session", t);
}
}
}
if (mustSessionBeFlushed) {
try {
log.debug("flushing hibernate session");
session.flush();
} catch (Throwable t) {
throw new JbpmPersistenceException("couldn't flush hibernate session", t);
}
}
if (mustSessionBeClosed) {
try {
log.debug("closing hibernate session");
session.close();
} catch (Throwable t) {
throw new JbpmPersistenceException("couldn't close hibernate session", t);
}
}
if (mustConnectionBeClosed) {
try {
log.debug("closing jdbc connection");
connection.close();
} catch (Throwable t) {
throw new JbpmPersistenceException("couldn't close jdbc connection", t);
}
}
}