Hibernate transaction not successfully started

后端 未结 7 2047
梦谈多话
梦谈多话 2020-12-31 00:15

Consider this simple Hibernate scenario:

session = getHibernateSession();
tx = session.beginTransaction();
SomeObject o = (SomeObject) session.get(SomeObject         


        
7条回答
  •  悲&欢浪女
    2020-12-31 00:59

    I got to know that this is already solved; even though I am posting my answer here.

    I haven't found wasCommitted() method on the transaction.

    But the following code worked for me:

    // commit only, if tx still hasn't been committed yet by Hibernate
    if (tx.getStatus().equals(TransactionStatus.ACTIVE)) { 
        tx.commit();
    }
    

提交回复
热议问题