Eviction requires deep knowledge of object internals. I’d like to have a magic spell which refresh 1 level cache in a single call.
You could control what needs to be detached in the object graph through CascadeType.DETACH
on associations.
with
null
s in some lazy loaded relations
You have three options.
- Maintain the associations yourself.
- Refresh the entities. Note that you can control how an object graph is refreshed with
CascadeType.REFRESH
on the associations. - Clear the
EntityManager
/Session
afterflush
to let Hibernate reload the entities when needed.