If i have transactional method like the one below, when is the finally block executed in case of transaction commit and rollback? For example if “persist some entity in database with hibernate” throws some hibernate exception which is true?
1) transaction rollback
2) finally block is executed
or
1) finally block is executed
2) transaction rollback
public void someTransactionalPersist(...) {
try {
// persist some entity in database with hibernate
} finally {
// do something
}
}
In both case finally block will executed finally.
sequence will be, If your try block throw exception then it will
rollbackfirst and thenfinallyblock willexecuted.