一尘不染

休眠NoCacheRegionFactoryAvailableException

hibernate

我收到了一个我无法解释的奇怪的Hibernate异常。告诉我我正在使用二级缓存,但是没有在哪里hibernate.cfg.xml指定二级缓存。这是例外:

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 class name to property
hibernate.cache.region.factory_class (and make sure the second level cache provider,
hibernate-infinispan, for example, is available in the classpath).
    at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:69)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:348)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
    at net.me.myapp.common.dao.SessionFactoryProvider.newSessionFactory(SessionFactoryProvider.java:37)
    at net.me.myapp.common.dao.BaseDAO.doPersist(BaseDAO.java:28)
    at net.me.myapp.common.dao.WordDAO.deleteAllWords(WordDAO.java:36)
    at net.me.myapp.tools.dmapper.DictionaryMapper.run(DictionaryMapper.java:88)
    at net.me.myapp.tools.dmapper.DictionaryMapper.main(DictionaryMapper.java:56)

而我的hibernate.cfg.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- DataSource & Connection info. -->
        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
        <property name="hibernate.connection.driver.class">org.h2.Driver</property>
        <property name="hibernate.connection.url">jdbc:h2:file:/${MYAPP_HOME}/data/myapp</property>
        <property name="hibernate.connection.username">myapp</property>
        <property name="hibernate.connection.password">mypassword</property>
        <property name="hibernate.connection.pool_size">1</property>

        <!-- General Hibernate settings. -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="use_sql_comments">true</property>

        <!-- DDL Mode. -->
        <property name="hbm2ddl.auto">validate</property>

        <!-- All our Hibernate mapping XML files. -->
        <mapping class="net.me.myapp.common.dto.WordDTO" />
    </session-factory>
</hibernate-configuration>

有什么想法会触发此异常吗?提前致谢!


阅读 214

收藏
2020-06-20

共1个答案

一尘不染

Pau在hibernate.cfg.xml中写了hibernate.cache.region.factory_class:

唯一的例外是不言而喻的。您必须设置 hibernate.cache.region.factory_class
属性。例如,使用ehcache将添加以下行:

<property

name=”hibernate.cache.region.factory_class”>net.sf.ehcache.hibernate.EhCacheRegionFactory

2020-06-20