|
According to the documentation:
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.
This causes that after especiallu update or delete the first level cache contains old entities. Of course it is possible to use one of refresh methods, however in many cases it remains unknown which entities were actually modified by DML statement, eg.:
update Entity set name="Johnny" where name="Henry"
In this case current refresh methods are useless, because it is unknown which Entities were actually loaded on current session, so it is not possible to refresh loaded ones.
I suggest to add Session.refresh(Class entityClass) method that will refresh all entities of given class, that were already loaded into session. This way it would be possible to run such refresh after certain DML statements. It is of course only an approximation, but it seems good enough.
It would even probably be possible to run such a refresh automatically after HQL query executeUpdate() as often such queries work with known Entity, but I am not convinced that such automatic solution would be always fine so, this should be somehow configurable just in case.
|