Hibernate transaction not successfully started

后端 未结 7 2014
梦谈多话
梦谈多话 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 01:13

    Well, it looks like once we reach the tx.commit() line, the transaction has already been committed. My only guess is that Hibernate already commits the transaction when get()ing the object.

    The fix for this is simple:

    // commit only if tx still hasn't been committed yet (by hibernate)
    if (!tx.wasCommitted())
        tx.commit();
    

提交回复
热议问题