禁用eclipselink缓存和查询缓存-不起作用? [英] Disable eclipselink caching and query caching - not working?

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

问题描述

我正在使用eclipselink JPA和一个数据库,该数据库也在我的应用程序外部进行更新。因此,有些表我想每隔几秒钟查询一次。即使尝试禁用缓存和查询缓存,我也无法正常工作。例如:

I am using eclipselink JPA with a database which is also being updated externally to my application. For that reason there are tables I want to query every few seconds. I can't get this to work even when I try to disable the cache and query cache. For example:

EntityManagerFactory entityManagerFactory =  Persistence.createEntityManagerFactory("default");
EntityManager em = entityManagerFactory.createEntityManager();

MyLocation one = em.createNamedQuery("MyLocation.findMyLoc").getResultList().get(0);

Thread.sleep(10000);

MyLocation two = em.createNamedQuery("MyLocation.findMyLoc").getResultList().get(0);  

System.out.println(one.getCapacity() + " - " + two.getCapacity());

即使在我的应用程序处于睡眠状态时容量发生变化,println也会始终为一个和两个打印相同的值。

Even though the capacity changes while my application is sleeping the println always prints the same value for one and two.

我在persistence.xml中添加了以下内容

I have added the following to the persistence.xml

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

我必须丢失某些东西,但想法不多了。

I must be missing something but am running out of ideas.

詹姆斯

推荐答案

问题是您正在阅读PersistenceContext / EM,它维护了以下对象的对象事务视图

The issue is you are reading through the PersistenceContext/EM which maintains an Object Transactional view of the data and will never update unless refreshed.

将查询刷新属性 eclipselink.refresh添加到find调用(JPA 2.0)或在调用之后简单地调用em.refresh。初步发现。

Add the query refresh property "eclipselink.refresh" to the find call (JPA 2.0) or simply call em.refresh after the initial find.

这篇关于禁用eclipselink缓存和查询缓存-不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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