禁用eclipselink缓存和查询缓存

编程入门 行业动态 更新时间:2024-10-12 18:15:35
本文介绍了禁用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缓存和查询缓存

本文发布于:2023-11-26 08:37:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   eclipselink

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!