实体是否默认缓存在jpa中? [英] Are entities cached in jpa by default?

查看:128
本文介绍了实体是否默认缓存在jpa中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将实体添加到我的数据库,它工作正常。但是当我检索List时,我得到了旧实体,我添加的新实体在我取消部署应用程序并再次重新部署之前不会显示。这意味着我的实体默认是缓存的吗?但是,我没有在persistence.xml或任何此类文件中对缓存实体进行任何设置。

I add entity to my database and it works fine. But when i retrieve the List, i get the old entity, the new entities i add are not shown until i undeploy the application and redeploy it again. This means are my entities cached by default? But, I haven't made any settings for caching entities in my persistence.xml or any such file.

我甚至尝试过调用flush(),refresh()和合并()。但它仍然只显示旧实体。我错过了什么吗?请帮帮我。

I have even tried calling flush(), refresh() and merge(). But still it shows the old entities only. Am i missing something? Please help me.

推荐答案

欢迎来到JPA。如果您使用它,这意味着如果您在JPA之外更新数据库,除非您知道自己在做什么并且非常小心,否则将会遇到大问题。这意味着您必须弄清楚如何刷新任何缓存的实体,以便可以重新加载它们。

Welcome to JPA. If you use it, it means you will have huge problems if you update the database outside of JPA unless you know what you're doing and are very careful. This means you have to figure out how to flush any cached entities so they can be reloaded.

基本上,如果您可以帮助它,请不要更新JPA之外的实体如果你这样做,你可能需要进入你的特定JPA提供者使用的缓存模型的工作。如果您需要在JPA之外进行更新,那么JPA可能不适合您。

Basically, don't update entities outside JPA if you can at all help it and if you do you will probably have to get into the workings of the caching model used by your particular JPA provider. If you need to update outside JPA a lot then JPA probably isn't the right choice for you.

这篇关于实体是否默认缓存在jpa中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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