将使用jpa特定代码

将使用jpa特定代码

本文介绍了休眠缓存(例如EHCache)将使用jpa特定代码(如果我使用EntityManager / EM Factory而不是Session / SessionFactory)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有非常简单的查询。我想确保我没有任何困惑。
我在规范中看到缓存不是规范的一部分,而是根据特定的orm工具提供者提供的。
我在我的应用程序中使用Hibernate作为ORM工具。但为了与供应商无关,我使用JPA(javax.persistence)的所有内容(注释,类等),而不是Hibernate特别提供的任何东西。
我使用 EntityManager 和 EntityManagerFactory 而不是 SessionFactory 和会话。
我的查询是在博客中,我看到由Hibernate提供的缓存提供者和缓存机制由Session(间接)处理。那么是否有可能 EntityManager 还可以用来缓存提供程序和缓存配置,因此指定为可缓存的实体和查询将能够使用缓存功能?
(我认为他们应该是)。
还有JPA提供的任何API(如Hibernate提供的统计信息API)来衡量和查看缓存统计信息?
请在这方面帮助我。

I have very simple query. I want to make sure that I don't have any confusion.I saw in the spec that caching is not a part of spec and is provided according to specific orm tool providers.I'm using Hibernate as an ORM tool in my application. But to be vendor independent I'm using everything (annotations, classes, etc) of JPA (javax.persistence) and not anything specifically provided by Hibernate.I'm using EntityManager and EntityManagerFactory instead of SessionFactory and Session.My query is that in the blogs I saw that cache providers and caching mechanism provided by Hibernate is taken care of by Session (indirectly). So is it possible that EntityManager will also be able to use to cache providers and cache configuration and hence the entities and queries specified as cacheable will be able to use the caching features?(I think they should be).Also is there any api provided by JPA (like Statistics api provided by Hibernate) to measure and view caching statistics?Please help me in this regards.

推荐答案

是的,它可以正常工作。如果你看看代码, EntityManagerImpl 委托给一个 SessionImpl ,所有的东西都可以像纯粹的hibernate一样工作。另请参阅关于JPA 2.0中的缓存

Yes, it will work just fine. If you look at the code, EntityManagerImpl delegates to a SessionImpl, so everything will work as with pure hibernate. Also check this article about caching in JPA 2.0

这篇关于休眠缓存(例如EHCache)将使用jpa特定代码(如果我使用EntityManager / EM Factory而不是Session / SessionFactory)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 04:40