Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the replacement for Hibernate's Transaction.wasCommitted method?

Tags:

java

hibernate

I'm trying to update some code from an old version of Hibernate (version 3). It uses two methods of the Transaction interface that no longer exist in Hibernate 5.

session.getTransaction().wasCommitted()
session.getTransaction().wasRolledBack()

What is the equivalent in Hibernate 5?

like image 385
Rob N Avatar asked Mar 17 '17 20:03

Rob N


1 Answers

You seem to be looking for session.getTransaction().getStatus(). For example,

session.getTransaction().getStatus() == TransactionStatus.COMMITTED
session.getTransaction().getStatus() == TransactionStatus.ROLLED_BACK

You may also want to examine the docs of TransactionStatus to see the relatively fine granularity of transaction statuses, as you might either want or need more inclusive substitutes than those above. Also, don't overlook TransactionStatus's methods, which you may find helpful. For example,

session.getTransaction().getStatus().isOneOf(
        TransactionStatus.MARKED_ROLLBACK,
        TransactionStatus.ROLLING_BACK,
        TransactionStatus.ROLLED_BACK)
like image 83
John Bollinger Avatar answered Oct 12 '22 23:10

John Bollinger