Providing Hibernate Entity Hidden Information

Assuming I have an object that maps to Hibernate ( E), and a view that queries the table of the object also displayed with Hibernate ( V).

If I save the instance Eand then query Vin the same session, then hibernate does not clear the persistence queue, because it does not know that these two objects are connected, and therefore, the result of the query Vwill not be correct.

I am currently clearing the session manually, but I find this an unsatisfactory solution, as it involves too much knowledge about how the mappings are performed.

What other options are there to validate view queries?

+3
source share
1 answer

The easiest approach is to use @Synchronize.

This behavior is controlled EntityPersister.getQuerySpaces().

You can try to override this method and configure Hibernate to use your custom persister with annotation @Persister. Check SessionImpl.autoFlushIfRequired()in the debugger to find out what these spaces should look like (I think they are the names of the dependent tables).

+2
source

All Articles