java - hibernate NoCacheRegionFactoryAvailableException

标签 java hibernate caching

我遇到了一个我无法解释的奇怪的 Hibernate 异常。它告诉我我正在使用二级缓存,但在 hibernate.cfg.xml 中我没有指定二级缓存。这是异常(exception)情况:

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>

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

最佳答案

Pau写在 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>

关于java - hibernate NoCacheRegionFactoryAvailableException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19303348/

相关文章:

Java NoClassDefFoundError

mysql - 我怎么知道什么时候该切换到执行从 MySQL 查询到 Redis 的读取操作?

apache-flex - Adobe Flex .swf 缓存

asp.net - .NET 4.0 ObjectCache 的线程安全和范围管理

java - 如何修复 java.util.NoSuchElementException 错误

hibernate - 我可以使用 Spring/Hibernate/c3p0 为多个数据库使用一个池数据源吗?

java - 建议 GWT 大规模应用服务器

java webpart 像asp.net 一样吗?

java - 我的对象没有在我的主函数中被调用

java - 在 Eclipse 中运行 docker 构建的项目