Re-introducing entity as proxied to the Session after "persist" a "new" object

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.

  1. Maintain the associations yourself.
  2. Refresh the entities. Note that you can control how an object graph is refreshed with CascadeType.REFRESH on the associations.
  3. Clear the EntityManager/Session after flush to let Hibernate reload the entities when needed.
1 Like