title: could not instantiate RegionFactory
body: <p>I am trying to enable secondary cache, but i am getting exception.</p>
  
  <p>Code for secondary cache in persistence.xml is given below:</p>
  
  <pre><code>            &lt;property name="hibernate.cache.use_second_level_cache" value="true"/&gt;
              &lt;property name="hibernate.cache.use_query_cache" value="true"/&gt;
              &lt;property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.EhCache"/&gt;
          &lt;/properties&gt;
  </code></pre>
  
  <p>Stacktrace for exception is:</p>
  
  <pre><code>Exception in thread "main" java.lang.ExceptionInInitializerError
      at com.org.JPAUtil.&lt;clinit&gt;(JPAUtil.java:21)
      at com.org.Main.main(Main.java:23)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
      at java.lang.Class.getConstructor0(Class.java:2714)
      at java.lang.Class.getConstructor(Class.java:1674)
      at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:409)
      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:280)
      at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)
      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
      at com.org.JPAUtil.&lt;clinit&gt;(JPAUtil.java:17)
      ... 6 more
  Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.CacheException
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      ... 20 more
  </code></pre>
  
  <p>After adding jar for ehcache, I'm getting exception as</p>
  
  <pre><code>Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.EhCache]
  at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:423)
      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:280)
      at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)
      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
  ... 10 more
  Caused by: java.lang.InstantiationException: org.hibernate.cache.EhCache
      at java.lang.Class.newInstance0(Class.java:357)
      at java.lang.Class.newInstance(Class.java:325)
      at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:419)
      ... 15 more
  </code></pre>