title: application properties for hibernate second level caching
body: <p>I have following properties in my Spring Boot application.properties file :</p>
  
  <pre><code>spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  
  spring.datasource.url=jdbc:mysql://localhost:3306/coupie
  spring.datasource.username=root
  spring.datasource.password=password
  
  
  spring.jpa.show-sql=true
  spring.jpa.hibernate.ddl-auto=none
  spring.jpa.properties.hibernate.id.new_generator_mappings=false
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
  spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
  
  #caching
  
  spring.jpa.properties.hibernate.cache.use_second_level_cache=true
  spring.jpa.properties.hibernate.cache.use_query_cache=true
  spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
  </code></pre>
  
  <p>When I run my springboot application , it fails with following stacktrace :</p>
  
  <pre><code> org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
      at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:66) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.hibernate.cache.spi.RegionFactory.buildEntityRegion(RegionFactory.java:132) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.hibernate.internal.CacheImpl.determineEntityRegionAccessStrategy(CacheImpl.java:439) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:120) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:300) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:460) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
      at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:535) ~[spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
      at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:519) ~[spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
      at com.coupie.mainapp.AppConfig.getSessionFactory(AppConfig.java:65) ~[classes/:na]
  </code></pre>
  
  <p>Any idea , how to fix this ? I can find examples online where in this case we add <code>hibernate.cache.region.factory_class</code> property in <code>hibernate.cfg.xml</code> , but here we have already added that in our <code>application.properties</code> in file .</p>
  
  <p>My <code>pom.xml</code> relevant dependencies :</p>
  
  <pre><code>&lt;dependencies&gt;
     &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
     &lt;/dependency&gt;
     &lt;dependency&gt;
        &lt;groupId&gt;mysql&lt;/groupId&gt;
        &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
     &lt;/dependency&gt;
     &lt;!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache --&gt;
     &lt;dependency&gt;
        &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
        &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
     &lt;/dependency&gt;
     &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache --&gt;
     &lt;dependency&gt;
        &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;
     &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>