|
I'm surprised by the dismissal of this ticket.
User.findAllByNickName('Bob').each{ it.nickName == 'Bob'}
This failure doesn't make logical sense to me, and the linked documentation does not seem to explain it. From troubleshooting, we've discovered that the sequence of events is as follows:
-
The User.findAllByNickName triggers a Hibernate query to the database
-
Hibernate finds a collection of matching records
-
Hibernate add any missing records to the first-level cache
-
Records already in the first-level cache are skipped
The last point seems like a missed opportunity. If the record is in the first-level cache and is not marked as dirty, but the data returned from the query does not match, wouldn't it make sense to update the object in the first-level cache with the new values?
If I try to write the object, optimistic locking will catch that it was updated behind the scenes, but the read operation does not seem to check or care. I'm most confused that the data is actually queried but then not used for a sanity check here.
I don't expect Hibernate to magically know when an object is updated concurrently in the database, that would be unreasonable. However, when Hibernate re-queries the object based on some criteria and then the criteria doesn't match in the code, that is totally unexpected.
|