Quote:
Why would it already returned the modified object with the name Bert?, as it's only located in the session and we didn't flush yet.
It's is true that in the db the query will find Adam and Anton, but in the Hibernate session Anton has been renamed to Bert. Since a single Hibernate session only can contain one object representing the Anton row it will return the very same instance that has already has it's name changed to Bert.
Just to make things clear, this only happens when everything happens in a single Hibernate session without flushing anything to the database or evict()-ing anything from the session. The default (AUTO) flush mode in Hibernate will flush the changes to the database before the query is executed and then the query would only find Adam.
Quote:
Can somebody give me a few examples when this occurs ? As can't realy think of some in my case...
Well, the example with Anton and Bert was maybe not a very good example, but in real world I guess things like this could happen when you least expect it.
Regarding the transaction isolation level there is also a REPEATABLE_READ isolation level (at least in some databases). With this level, a given query will always return the same result if it is repeated in the same transaction, even if things have been updated by the same or other committed transactions. So, I guess with this isolation level it would make sense to not flush the session, since it will not affect the result of the query. If you are going for this transaction isolation level you might just as well go for the FlushMode.COMMIT as well.