d1x d1x - 2 months ago 12x
Java Question

EntityManager refresh

I have web application using JPA. This entity manager keeps bunch of entites and suddenly I update the database from other side. I use MySQL and I use PhpMyAdmin and change some row. How to tell entity manager to re-synchronize, e.g. to forgot all the entites in cache? I know there is

method, but is there any possibility how to do
or something what results in this? It is sure this is expensive operation but if it has to be done.


Refresh is something different since it modifies your object. This line will just empty the cache, so if you fetch objects changed outside the entity manager, it will do an actual database query instead of using the outdated cached value.