EntityManager 刷新 [英] EntityManager refresh

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

问题描述

我有使用 JPA 的 Web 应用程序.这个实体管理器保留了一堆实体,突然我从另一端更新了数据库.我使用 MySQL 并使用 PhpMyAdmin 并更改了一些行.

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

我知道有 refresh(Object) 方法,但是有没有可能怎么做 refreshAll() 或者什么导致这个?

这肯定是昂贵的操作,但如果必须这样做.

解决方案

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

Refresh 有所不同,因为它修改您的对象.这一行只会清空缓存,因此如果您在实体管理器之外获取更改的对象,它将执行实际的数据库查询,而不是使用过时的cached 值.>

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.

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

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天全站免登陆