Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:41:07+00:00 2026-06-11T21:41:07+00:00

I am trying to enable secondary cache, but i am getting exception. Code for

  • 0

I am trying to enable secondary cache, but i am getting exception.

Code for secondary cache in persistence.xml is given below:

            <property name="hibernate.cache.use_second_level_cache" value="true"/>
            <property name="hibernate.cache.use_query_cache" value="true"/>
            <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.EhCache"/>
        </properties>

Stacktrace for exception is:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.org.JPAUtil.<clinit>(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.<clinit>(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

After adding jar for ehcache, I’m getting exception as

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:41:08+00:00Added an answer on June 11, 2026 at 9:41 pm

    Instead of:

    <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.EhCache"/>
    

    Use:

    <property name="hibernate.cache.provider_class"  value="org.hibernate.cache.EhCacheProvider"/>
    

    For example, using Hibernate 4.x along with the JAR files hibernate-ehcache-4.3.10.Final.jar and slf4j-api-1.6.1.jar, modify persistence.xml:

    <properties>
      <!-- ... other properties ... -->
      <property name="hibernate.show_sql" value="false"/>
      <property name="hibernate.format_sql" value="false"/>
      <property name="hibernate.cache.use_second_level_cache" value="true"/>
      <property name="hibernate.cache.provider_class"  value="org.hibernate.cache.EhCacheProvider"/>
    </properties>
    

    Then ensure that hibernate-ehcache-4.3.10.Final.jar and slf4j-api-1.6.1.jar are deployed to JBoss.

    Do not include ehcache-core-2.4.3.jar.

    Now you can annotate entities, such as:

    @Entity
    @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "region_name")
    public class MyEntity implements Serializable {
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I' m trying to enable adding/deleting rows to/from table using folowing code: Script: $(document).ready(function()
I am trying to enable a disabled tab in Jquery but it doesn't work.
When I'm trying to enable auto_increment on a column in phpmyadmin, but I always
I am trying to enable/disable radiobuttonlist with javascript code. This javascript is working fine
when trying to enable and reindex Product Flat Data - getting error from magento
I am trying to enable users to change their password. I keep getting the
When i am trying to enable the shard... I am getting following errors........ use
Hello im trying to enable my JMenuItem from within an event listener but it
been trying to enable crosshairs on highcharts.... on jsfindle the example works fine, but
I am trying to enable and disable a required field validator using javascript but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.