Hibernate transaction not successfully started

后端 未结 7 2051
梦谈多话
梦谈多话 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:53

    This is a really old question and I figure you've already solved it (or given up on Hibernate) but the answer is tragically simple. I'm surprised no one else picked it up.

    You haven't done a session.save(o), so there is nothing in the transaction to commit. The commit may still not work if you haven't changed anything in the object, but why would you want to save it if nothing has changed?

    BTW: It is also perfectly acceptable to do the session.get(...) before the session.beginTransaction().

提交回复
热议问题