I have an application that uses 2nd level cache on a JBoss AS 7 installation (Infinispan 2nd level cache provider).
We have some update JPQL Queries that invalidate the cache- I wonder what will be the effect if we include some native SQL queries in our application. Will the Query cache be invalidated ?
Also I remember using the sqlQuery.addSynchronizedQuerySpace("") instruction on Hibernate to prevent cache invalidation for some native SQL queries. Is it possible to do it also with JPA ?
Thanks!
相关问题
- JPA one-to-many association to an entity with @Inh
- How does the JPA handle partial, non-disjoint inhe
- How can I access the repository from the entity in
- Should there be an EntityManager per thread in Spr
- JPA and eclipselink - Overriding FetchType.Eager
相关文章
- 这个SpringBoot 2.2.x,怎么判断?
- Hibernate doesn't generate cascade
- how to set H2 primary key id to auto_increment?
- JBoss Deploying non-JDBC-compliant driver class co
- Writing CRUDRepository's findBy() method on a
- QueryDSL Window functions
- JPA cascade persist - many to one
- How to left join unrelated entities?
I came across this question when dealing with the same problem today, so I thought I'd post my findings here.
Using JPA native UPDATE/INSERT/DELETE queries does cause Hibernate to invalidate the entire 2nd level entity cache. As you mentioned in your question, Hibernate has a workaround for this, but it seems to not be possible to do the equivalent of Hibernate's
addSynchronizedQuerySpace()
,addSynchronizedEntityClass()
andaddSynchronizedEntityName()
using pure JPA.What JPA however does allow you to do is to
unwrap
a JPAQuery
object to gain access to the JPA provider's API. If you're using Hibernate as a JPA provider, this will then allow you to use Hibernate'saddSynchronizedXxx
methods as follows:It's not an ideal solution, but it will effectively allow you to prevent the entire second level cache from being invalidated.