sabyasachi3.cse
sabyasachi3.cse

Reputation: 49

Using Multiple Transaction in a Single Hibernate Session

I have an web application with MySQL DB and Hibernate. I have open a Hibernate Session,

started a transaction

do some work

commit the transaction

Then again

started a transaction

do some work

commit the transaction

But I am ended with following exception

Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started Transaction not successfully started.

Please guide me in this specific issue. How can I use multiple transaction within a Session.

Upvotes: 1

Views: 1208

Answers (1)

bitkot
bitkot

Reputation: 4504

I think you are not starting your transaction. That is when you get that exception. You have opened a session, but before beginning transaction, you are committing it. Try beginning it after you open the session.

// create session
try {    
    tx = session.beginTransaction();
    // do something
    tx.commit();
} catch (Exception exp) {
    tx.rollback();

}

try {    
    tx = session.beginTransaction();
    // do something
    tx.commit();
} catch (Exception exp) {
    tx.rollback();

}
// close session

Upvotes: 1

Related Questions