title: Unable to configure second level cache of hibernate-ehcache-4.3.5.Final.jar in Hibernate 5.1.0.Final
body: <p>I'm trying to achieve second level cache in my Java EE project using Hibernate. My Hibernate version is 5.1.0.Final. I've created a table <code>employee</code> in my MySQL database. I've included <code>hibernate-ehcache-4.3.5.Final.jar</code> in my project, but it's throwing <code>Unable to create requested service [org.hibernate.cache.spi.RegionFactory]</code> error. Here is the <code>hibernate.cfg.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
   &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/intu&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;****&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;****&lt;/property&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
       &lt;property name="hibernate.cache.region.factory_class"&gt;net.sf.ehcache.hibernate.EhCacheRegionFactory&lt;/property&gt;
       &lt;property name="cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/property&gt;  
  &lt;property name="hibernate.cache.use_second_level_cache"&gt;true&lt;/property&gt;  
  
  
  
   &lt;property name="show_sql"&gt;false&lt;/property&gt;
   &lt;property name="format_sql"&gt;true&lt;/property&gt;
   &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
   &lt;mapping class="com.dom.Employee"/&gt;  
  
   &lt;/session-factory&gt;
   &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>My <code>Employee</code> class:</p>
  
  <pre><code>package com.intu;
  
  import javax.persistence.Entity;
  import javax.persistence.Table;
  
   import org.hibernate.annotations.Cache;
   import org.hibernate.annotations.CacheConcurrencyStrategy;
  
   @Entity
   @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
   @Table(name = "employee")
   public class Employee {
      private int id;
      private String name;
  
  
      public Employee() {
      }
  
      public Employee(String name, float salary) {
          super();
          this.name = name;
      }
  
      public int getId() {
           return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }  
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      } 
  }
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>package com.test;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  
  import com.intu.Employee;
  import com.util.HibernateUtil;
  
  public class Ehcache {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          System.out.println(org.hibernate.Version.getVersionString());
          SessionFactory factory = HibernateUtil.getSessionFactory();
          Session session1=factory.openSession();  
          Employee emp1=(Employee)session1.load(Employee.class,121);  
          System.out.println(emp1.getId()+" "+emp1.getName());  
          session1.close();  
  
          Session session2=factory.openSession();  
          Employee emp2=(Employee)session2.load(Employee.class,121);  
          System.out.println(emp2.getId()+" "+emp2.getName());  
          session2.close();   
      }
  }
  </code></pre>
  
  <p>The error is</p>
  
  <pre><code>eb 23, 2016 3:10:49 PM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {5.1.0.Final}
   Feb 23, 2016 3:10:49 PM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Feb 23, 2016 3:10:49 PM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Initial SessionFactory creation  failed.org.hibernate.service.spi.ServiceException: Unable to create requested  service [org.hibernate.cache.spi.RegionFactory]
  Exception in thread "main" java.lang.ExceptionInInitializerError
  at com.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:20)
  at com.util.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:7)
  at com.test.Ehcache.main(Ehcache.java:14)
  Caused by: org.hibernate.service.spi.ServiceException: Unable to create   requested service [org.hibernate.cache.spi.RegionFactory]
  at   org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
  at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
  at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
  at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.&lt;init&gt;(MetadataBuilderImpl.java:663)
  at org.hibernate.boot.internal.MetadataBuilderImpl.&lt;init&gt;(MetadataBuilderImpl.java:127)
  at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:655)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
  at com.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
  ... 2 more
   Caused by: org.hibernate.HibernateException: could not instantiate    RegionFactory [net.sf.ehcache.hibernate.EhCacheRegionFactory]
  at   org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactor  yInitiator.java:84)
  at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactor  yInitiator.java:29)
  at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
  at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
  </code></pre>
  
  <p>I'm not sure what exactly is missing. What should be added more to get it working?</p>