EntityManager刷新 [英] EntityManager refresh

查看:107
本文介绍了EntityManager刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用JPA的Web应用程序。这个实体管理器保留了大量的参与者,突然我从另一侧更新了数据库。我使用 MySQL ,我使用 PhpMyAdmin 并更改了一些行。

I have web application using JPA. This entity manager keeps bunch of entites and suddenly I update the database from other side. I use MySQL and I use PhpMyAdmin and change some row.

如何告诉实体经理重新同步,例如忘记缓存中的所有entites?

How to tell entity manager to re-synchronize, e.g. to forgot all the entites in cache?

我知道有刷新(对象)的方法,但有没有办法怎么做 refreshAll()或者是什么导致了这个?

I know there is refresh(Object) method, but is there any possibility how to do refreshAll() or something what results in this?

确定这是一项昂贵的操作,但是如果必须这样做的话。

It is sure this is expensive operation but if it has to be done.

推荐答案

entityManager.getEntityManagerFactory().getCache().evictAll()

刷新是不同的,因为它修改了你的对象。这行只是清空缓存,所以如果你获取在实体管理器外部更改的对象,它将执行实际的数据库查询,而不是使用过时的缓存值。

Refresh is something different since it modifies your object. This line will just empty the cache, so if you fetch objects changed outside the entity manager, it will do an actual database query instead of using the outdated cached value.

这篇关于EntityManager刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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