Will hibernate cache (EHCache for eg) will work wi

2019-02-27 09:54发布

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条回答
萌系小妹纸
2楼-- · 2019-02-27 10:41

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

查看更多
登录 后发表回答