Reputation: 49
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
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