Search code examples
javahibernatehibernate-4.xhibernate-5.x

Replacement for org.hibernate.Transactions.isActive() in Hibernate 5


I'm migrating from hibernate 4.2.17 to 5.0.7 which works fine so far, but it seems that the method isActive is deprecated. I just can't use it anymore.

Here's my code:

public void starteTransaktion() {
        try {
            getMySession();

            if(!hibernateSession.getTransaction().isActive()) {
                hibernateSession.beginTransaction();
            }
        } catch (HibernateException e) {

        }
    }

I substituted all other methods, but I can't quite find a replacement for this...

Error message: The method isActive() is undefined for the type Transaction


Solution

  • As per 5.0 Javadoc:

    hibernateSession.getTransaction().getStatus() != TransactionStatus.ACTIVE