How to check if cache is being used or not?

#1

I am using infinispan as hibernate 2nd level cache.
I want to confirm that cache is working properly as I have upgraded hibernate from 3 to 5 and infinispan to from 3 to 8. I am using javax.persistence 2.0.0

Entity definition is something like
@Entity
@Cacheable
public class Alert {
}

@Transactional(readOnly = true)
public List findAll() {
return this.session.createCriteria(Alert.class) .list();
}

I am calling above method findAll every 5 min. As alert entity is cacheable, should the values be fetched by cache instead of going to the database?
< logger name=“org.hibernate.cache” level=“DEBUG”/>
I have enabled logging of cache but I don’t see any logs showing it is fetching from the cache instead of going to the database.

0 Likes

#2


I have added javax.persistence.sharedCache.mode=ENABLE_SELECTIVE

is there any hibernate property which i need to set ?

0 Likes

#3

Are you hoping to use the query cache?

I had the problem and I used the query hint org.hibernate.cacheable from Hibernate.

query.setHint("org.hibernate.cacheable", true);

JPA tells the provider (e.g. Hibernate) that you want to use this query property or hint.

0 Likes