Hibernate NoCacheRegionFactoryAvailableException

后端 未结 5 2107
自闭症患者
自闭症患者 2021-02-20 04:24

I\'m getting a bizarre Hibernate exception that I can\'t explain. It\'s telling me that I\'m using 2nd level cache, but no where in hibernate.cfg.xml do I specify a

相关标签:
5条回答
  • 2021-02-20 05:11

    Using the following line fixed it :

    <beans:entry key="hibernate.cache.use_second_level_cache" value="false"/>
    

    But the Hibernate message is probably a warning that we should use second level cache?

    0 讨论(0)
  • 2021-02-20 05:21

    This error is very misleading, I spent almost a day to finally figure out the root cause. Thought my hibernate config file has defined second level cache and factory class, it was giving me error that hibernate.cache.region.factory_class is not given.

    I see that by hibernate.cfg.xml file is also available in classpath. But even after any change in that there was no impact and getting same error.

    Finally I realized that for test purpose I have overridden persistence.xml file which has below missing properties under persistence-unit. After adding that issue was resolved.

     <properties>
                <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml" />
    </properties>
    

    So this means my application was not able to find hibernate.cfg.xml file and somehow instead of giving error related to missing configuration, it cries out for factory class.

    0 讨论(0)
  • 2021-02-20 05:23

    Pau wrote on hibernate.cache.region.factory_class Required in hibernate.cfg.xml:

    The exception is quite self-explanatory. You have to set the hibernate.cache.region.factory_class property. For instance with ehcache would be adding the following line:

    <property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
    
    0 讨论(0)
  • 2021-02-20 05:23

    I also received this error and took me a while to track down. At one point we were going to have multiple cache regions, but in the end decided we were just going to have one cache pool.

    When we merged that change into an older branch - we still had an entity with the old strategy of a cache pool per entity:

    @Entity
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="tableRegion")
    @Table(name = "table")
    public class table {
    

    By removing the Cache annotation - it resolved the org.hibernate.cache.NoCacheRegionFactoryAvailableException:

    @Entity
    @Table(name = "table")
    public class table {
    

    Figured I'd post in case anyone else had a similar situation

    0 讨论(0)
  • 2021-02-20 05:25

    These are the property you need to add to enable second level cache

    <!-- Provider for second level cache -->
            <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
            <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
    
    0 讨论(0)
提交回复
热议问题