Disable JPA EclipseLink 2.4 Cache

I am trying to disable the EclipseLink 2.4 cache, so if the data is changed in the database by other applications, the same data will be updated in my application that uses EclipseLink 2.4 without restarting it. None of these properties work:

<shared-cache-mode>NONE</shared-cache-mode> ... <property name="eclipselink.cache.shared.default" value="false"/> <property name="eclipselink.cache.size.default" value="0"/> <property name="eclipselink.cache.type.default" value="NONE"/> <property name="eclipselink.query-results-cache" value="false"/> <property name="eclipselink.refresh" value="true"/> 

The only thing that helped:

 typedQuery.setHint(QueryHints.REFRESH, HintValues.TRUE); 

But this is not an option for me, because now that this application is written, I do not want to look for all the requests or methods em.find() and insert this hint.

EDIT1: A similar problem is described here: http://eclipse.1072660.n5.nabble.com/Notifications-about-external-database-changes-td5389.html

EDIT2: To summarize, I would like all queries and search calls to update data taken from the database.

+4
source share
3 answers
 <shared-cache-mode>NONE</shared-cache-mode> or, <property name="eclipselink.cache.shared.default" value="false"/> 

Are the correct mechanisms. Or use the @Cache annotation for a specific class.

I assume the problem is that you are using the same EntityManager for both queries. EntityManager is also required to store the cache of all instances it manages. Constantly updating these objects may result in any changes made by your application to drop. (EntityManager is a transaction object).

You should create a new EntityManager for each request or transaction, or call clear () to delete its managed objects.

EclipseLink also supports WEAK EntityManagers, but the correct design will be to not have long EntityManager administrators.

+5
source

I think I have the same question . I just tried to clear all caches anyway through the cache persistence.xml properties (shared-cache, eclipselink-cache ...), but by chance I got old Entity instances, apparently without any templates .....

In no case!

+1
source

I create a new EntityManager for each request,

 <property name="eclipselink.query-results-cache" value="false"/> 

after changing the object via JPA in one request, then get the object in the next request, still get the OptimisticLocking problem. Try to find out the problem.

0
source

All Articles