Hibernate version: 3.0.5
Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction(); List fixes = session.createCriteria(Fix.class).list(); tx.commit();
Name and version of the database you are using:
Apache Derby, 10.0.2.0
The generated SQL (show_sql=true):
Hibernate: select this_.FIX_ID as FIX1_0_, ... from FIX this_ Hibernate: update FIX set VERSION=?, ... where FIX_ID=? and VERSION=? Hibernate: update FIX set VERSION=?, ... where FIX_ID=? and VERSION=? Hibernate: update FIX set VERSION=?, ... where FIX_ID=? and VERSION=? Hibernate: update FIX set VERSION=?, ... where FIX_ID=? and VERSION=? Hibernate: update FIX set VERSION=?, ... where FIX_ID=? and VERSION=?
In my application, there is class Fix, that has field:
private int version; // for optimistic locking
When executing the code shown above, Hibernate will issue an "update" when the transaction is committed, which increases the version counter (see the generated SQL, as shown above - there are 5 objects returned by the select).
Now my question is: why does Hibernate issue the update, even when there was no session.update()?
I found this behaviour at all isolation levels (1, 2, 4).
This might result in one of two concurrent readers (both executing the same above code) receiving a StaleObjectStateException at Transaction.commit().
I've read the book and browsed the forum, but couldn't find an aswer to that question. Mabe I'm overlooking s.th.?
|