Home Does Hibernate query caching have any effect if it's used as a JPA provider only?
Reply: 1

Does Hibernate query caching have any effect if it's used as a JPA provider only?

Karl Richter
1#
Karl Richter Published in 2018-02-10 18:52:36Z

This question already has an answer here:

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

Hibernate offers to select different cache providers for query and L2 caching, but there seems to be no clear statement whether this has an effect if Hibernate is used as plain JPA provider only, i.e. by running queries with EntityManager instead of Session. All introductions simply speak of Hibernate which can mean Hibernate with Hibernate-specific features or Hibernate as JPA provider and then provide code examples involving Hibernate - to advertise the use or because it's a necessity?

In case that matters, I'm referring to a Java EE environment.

Anton Tupy
2#
Anton Tupy Reply to 2018-02-11 12:52:45Z

Use of the caching provider is only a matter of configuration of Hibernate. EntityManager is only thin wrapper around Session. FYI since Hibernate version 5.2 Session extends EntityManager, see https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/Session.html .

So answer is - Hibernate uses all of their power even when used through JPA.

EDIT:

You can ensure that EntityManager is wrapper around Session by code like this:

EntityManager em = ...; // Get EntityManager from somewhere
Session session = em.unwrap(Session.class);

If you use Hibernate then you will successefully get session wrapped by EntityManager and can to use it directly.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.324845 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO