Search code examples
cachingjpa-2.0eclipselink

Disabling EclipseLink cache


In my application, when user logs in to the system the system reads some setting from DB and stores them on user's session. The system is performing this action by a JPA query using EclipseLink (JPA 2.0).

When I change some settings in DB, and sign in again, the query returns the previous results. It seems that EclipseLink is caching the results.

I have used this to correct this behavior but it does not work:

query.setHint(QueryHints.cache_usage,cacheUsage.no_cache);

Solution

  • If you want to set query hints, the docs recommend doing:

    query.setHint("javax.persistence.cache.storeMode", "REFRESH");
    

    You can alternately set the affected entity's @Cacheable annotation

    @Cacheable(false)
    public class EntityThatMustNotBeCached {
    ...
    }