Quote:
Instead it always returns the existing object in session.
This is expected and documented in
http://docs.jboss.org/hibernate/stable/ ... tch-directQuote:
This means that manipulating data directly in the database (using the SQL Data Manipulation Language (DML) the statements: INSERT, UPDATE, DELETE) will not affect in-memory state.
The possible solutions are:
* Call session.evict() before the second query
* Call session.evict(entity) before the second query
* Use session.refresh(entity) which has been designed with this use case in mind:
Quote:
This method is, however, useful in certain special circumstances. For example
...
* after executing direct SQL (eg. a mass update) in the same session