Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 968
Pascal Petruch Avatar asked Jan 15 '16 10:01

Pascal Petruch


People also ask

What is the use of @transactional in hibernate?

The @Transactional annotation is the metadata that specifies the semantics of the transactions on a method. We have two ways to rollback a transaction: declarative and programmatic. In the declarative approach, we annotate the methods with the @Transactional annotation.

How hibernate handle multiple transactions?

Therefore, you can run multiple transactions on the same Hibernate Session, but there's a catch. Once an exception is thrown you can no longer reuse that Session. My advice is to divide-and-conquer. Just split all items, construct a Command object for each of those and send them to an ExecutorService#invokeAll .


1 Answers

As per 5.0 Javadoc:

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

like image 184
mindas Avatar answered Sep 28 '22 01:09

mindas