Assuming that I have an entity which is mapped with Hibernate (E) and a view which queries the table of the entity, also mapped with Hibernate (V).
If I persist an instance of E and then query V in the same session, then hibernate does not flush the persistence queue since it does not know that the two entities are related, and therefore the result of the query on V will be incorrect.
I am currently flushing the session manually, but I find this a unsatisfying solution, since it assumes too much knowledge about the way the mappings are done.
What other options are there to make sure queries over views are correct?
The most straightforward approach is to use
@Synchronize.This behaviour is controlled by
EntityPersister.getQuerySpaces().You can try to override that method and configure Hibernate to use your custom persister with
@Persisterannotation. CheckSessionImpl.autoFlushIfRequired()in debugger to find out how that spaces should look like (I guess they are names of dependent tables).