Will hibernate cache (EHCache for eg) will work with jpa specific code (if I use EntityManager/EM Factory instead of Session/SessionFactory)?

元气小坏坏 提交于 2020-02-15 11:21:27

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/5132017/will-hibernate-cache-ehcache-for-eg-will-work-with-jpa-specific-code-if-i-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!