Search code examples
javajpaentitymanager

Difference between evictAll and refresh


What is the difference between evictAll and refresh :

em.getEntityManagerFactory().getCache().evict(AdminUtilisateur.class, user);

and

em.refresh(em.getReference(AdminUtilisateur.class, user.getId()));

And when should i use each one?

Thank you.


Solution

  • evict : Mark an instance as no longer needed in the cache.

    refresh : Refresh the state of the instance from the database, overwriting changes made to the entity