# How to check if cache is being used or not?

**URL:** https://discourse.hibernate.org/t/how-to-check-if-cache-is-being-used-or-not/2462
**Category:** Hibernate ORM
**Created:** [March 20, 2019, 10:27am UTC](https://discourse.hibernate.org/t/how-to-check-if-cache-is-being-used-or-not/2462 "2019-03-20T10:27:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sandeep\_kamath](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/sandeep_kamath/32/817_2.png) [@sandeep\_kamath](https://discourse.hibernate.org/u/sandeep_kamath)
#### Post date: [March 20, 2019, 10:27am UTC](https://discourse.hibernate.org/t/how-to-check-if-cache-is-being-used-or-not/2462/1 "2019-03-20T10:27:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sandeep\_kamath](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/sandeep_kamath/32/817_2.png) [@sandeep\_kamath](https://discourse.hibernate.org/u/sandeep_kamath)
#### Post date: [March 20, 2019, 1:30pm UTC](https://discourse.hibernate.org/t/how-to-check-if-cache-is-being-used-or-not/2462/2 "2019-03-20T13:30:13Z")

</div>

> <https://stackoverflow.com/questions/3663979/how-to-use-jpa2s-cacheable-instead-of-hibernates-cache>

  
I have added javax.persistence.sharedCache.mode=ENABLE\_SELECTIVE

is there any hibernate property which i need to set ?

---

<div class="post-metadata">

### Author: ![Varona\_Gregg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/varona_gregg/32/518_2.png) [@Varona\_Gregg](https://discourse.hibernate.org/u/Varona_Gregg)
#### Post date: [March 29, 2019, 4:12am UTC](https://discourse.hibernate.org/t/how-to-check-if-cache-is-being-used-or-not/2462/3 "2019-03-29T04:12:44Z")

</div>

Are you hoping to use the query cache?

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

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

```

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