Hibernate has a Stateless Version of its Session: Does something similar exist for the JPA EntityManager? I.e. an EntityManager that does not use the first level cache?
From JPA point of view:
javax.persistence.EntityManager
stands for 1st level cache (persistence context, transactional cache)javax.persistence.EntityManagerFactory
stands for 2nd level cache (shared cache)A given persistence provider may implement additional caching layers. Additionally JDBC Driver API may be treated as low-level cache for storing columns/tables and caching connections/statements. It's however transparent to JPA.
Both javax.persistence.EntityManager and org.hibernate.StatelessSession offer similar APIs.
You cannot disable 1st level cache with EntityManager beacuse these two things are equivalent. You can however:
createQuery
, createNamedQuery
, createNativeQuery
for querying and bulk updates/deletes (the persistence context is not updated to reflect their results). Such queries should be executed in their own transaction thus invalidating any cached entities, if any. Transaction-scoped entity manager (means stateless) should be used as well.<shared-cache-mode>NONE</shared-cache-mode>
in persistence.xml or javax.persistence.sharedCache.mode
in propertiesNot part of the JPA API or spec. Individual implementations may allow disabling the L1 cache. DataNucleus JPA, the one I have used, does allow this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With