0

When I try to delete an object using HQL, I use hiberate's session.CreateQuery().executeUpdate() and it returns 1 item is deleted. However, in database, nothing has been deleted. After executeUpdate, I also did flush.

Could anyone give me some suggestion about what's wrong here?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
lucky_start_izumi
  • 2,511
  • 13
  • 41
  • 61

1 Answers1

2

You haven't committed an enclosing transaction. You need something like:

tx = session.beginTransaction()
session.createQuery().executeUpdate("...")
tx.commit()
Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
  • May I ask why I didn't use transaction when I insert new obs into db, but it still works well?Thank you very much:) – lucky_start_izumi Dec 22 '11 at 18:26
  • There are a multitude of reasons that vary by database vendor. Ultimately it comes down to this: the database you were using wasn't transactional, one of your connections was at a different isolation level, allowing uncommitted changes to be seen, autocommit was on (everything was committed as it happened), or there *was* a transaction and you just didn't know it. – Ryan Stewart Dec 22 '11 at 18:40