title: Spring Boot with Hibernate Second Level cache
body: <p>I trying to use a second level cache so I put in my pom.xml</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;
          &lt;version&gt;5.2.2.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>in my application.properties</p>
  
  <pre><code>spring.jpa.properties.hibernate.cache.use_second_level_cache=true
  spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
  </code></pre>
  
  <p>And I put to hibernate generate statistics</p>
  
  <pre><code>spring.jpa.properties.hibernate.generate_statistics=true
  logging.level.org.hibernate.stat=DEBUG
  </code></pre>
  
  <p>And in my Entity I put</p>
  
  <pre><code>@Entity(name = "natureza")
  @Cacheable
  @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
  public class Natureza extends AbstractEntity{
  ...
  }
  </code></pre>
  
  <p>But how can I see if my cache are realy working.</p>
  
  <p>My hibernate log this:</p>
  
  <pre><code>2018-04-05 12:56:44.954 DEBUG 33410 --- [nio-8080-exec-4] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 42ms, rows: 21 
  
  2018-04-05 12:57:21.470 DEBUG 33410 --- [nio-8080-exec-7] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 21ms, rows: 21
  
  2018-04-05 12:57:40.938 DEBUG 33410 --- [nio-8080-exec-9] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 27ms, rows: 21
  
  2018-04-05 12:58:35.305 DEBUG 33410 --- [nio-8080-exec-2] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 18ms, rows: 21
  
  2018-04-05 12:59:04.187 DEBUG 33410 --- [nio-8080-exec-9] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 14ms, rows: 21
  </code></pre>
  
  <p>so then I remove the cache from my app and the hibernate log this:</p>
  
  <pre><code>2018-04-05 13:02:38.883 DEBUG 34669 --- [nio-8080-exec-3] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 50ms, rows: 21
  
  2018-04-05 13:02:58.744 DEBUG 34669 --- [nio-8080-exec-6] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 23ms, rows: 21
  
  2018-04-05 13:03:13.570 DEBUG 34669 --- [nio-8080-exec-4] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 12ms, rows: 21
  
  2018-04-05 13:03:32.779 DEBUG 34669 --- [nio-8080-exec-4] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 11ms, rows: 21
  
  2018-04-05 13:03:59.771 DEBUG 34669 --- [nio-8080-exec-4] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000117: HQL: SELECT * FROM natureza WHERE natureza_tipo_id = ?, time: 7ms, rows: 21
  </code></pre>
  
  <p>So the hibernate are more slowly with the cache enabled :D </p>
  
  <p>It`s possible to verify if the hibernate are creating the cached correctly? how? tks</p>