Disabling EclipseLink cache

爱⌒轻易说出口 提交于 2019-12-05 11:13:20

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 {
...
}

If you're returning a some kind of configuration entity and want to be sure that data is not stale, you can invoke em.refresh(yourEntity) after returning the entity from query. This will force the JPA provider to get fresh data from the database despite the cached one.

If you want to disable the L2 cache you can use <shared-cache-mode>NONE</shared-cache-mode> within <persistence-unit> in persistence.xml or use Cacheable(false) directly on your configuration entity.

If you're returning plain fields instead of entities and still getting stale data you may try clearing the PersistenceContext by invoking em.clear().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!