禁用JPA EclipseLink 2.4缓存 [英] Disable JPA EclipseLink 2.4 cache

查看:381
本文介绍了禁用JPA EclipseLink 2.4缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试禁用EclipseLink 2.4缓存,因此如果其他应用程序在数据库中更改了数据,则在我的应用程序中刷新相同的数据,该应用程序使用EclipseLink 2.4,而不重新启动它。这些属性似乎都不起作用:

I'm trying to disable EclipseLink 2.4 cache so if the data gets changed in DB by other applications, same data gets refreshed in my application, which is using EclipseLink 2.4, without restarting it. None of these properties seems to 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"/>

唯一有帮助的选择是:

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

但这对我来说不是一个选项,因为现在该应用程序已写入我不想搜索所有查询或 em.find()方法并将此提示放入。

But this is not an option for me, because now that application is written I don't want to search for all queries or em.find() methods and put this hint in.

EDIT1: 此处描述了类似的问题: http ://eclipse.1072660.n5.nabble.com/Notifications-about-external-database-changes-td5389.html

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

EDIT2: 总结一下,我希望所有查询和查找调用都会刷新从数据库中获取的数据。

To summarize I would like that all queries and find calls would refresh data taken from database.

推荐答案

<shared-cache-mode>NONE</shared-cache-mode>
or,
<property name="eclipselink.cache.shared.default" value="false"/>

是否是正确的机制。或者对特定类使用@Cache批注。

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

我假设您发出的问题是您对两个查询使用相同的EntityManager。 EntityManager还需要维护它管理的所有实例的缓存。始终刷新这些对象会导致应用程序所做的任何更改被丢弃。 (EntityManager是一个事务对象)。

I assume you issue is that you are using the same EntityManager for both queries. An EntityManager also is required to maintain a cache of all of the instances it manages. Always refreshing these objects would cause any changes your application had made to be discarded. (An EntityManager is a transactional object).

您应该为每个请求或每个事务创建一个新的EntityManager,或者调用clear()来丢弃其托管对象。

You should create a new EntityManager per request, or per transaction, or call clear() to discard its managed objects.

EclipseLink也支持WEAK EntityManagers,但正确的设计是没有长期存在的EntityManagers。

EclipseLink also supports WEAK EntityManagers, but the correct design would be to not have long lived EntityManagers.

这篇关于禁用JPA EclipseLink 2.4缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆