【问题标题】:JPA second level cache in wildfly8.2, hibernate-entitymanager 4.3.8.FinalWildfly8.2中的JPA二级缓存,hibernate-entitymanager 4.3.8.Final
【发布时间】:2023-03-08 00:53:02
【问题描述】:

我正在尝试在 wildfly8.2 中使用二级缓存 我正在通过 JavaConfig 设置属性 属性属性 = 新属性(); properties.setProperty("hibernate.hbm2ddl.auto", hibernateHbm2ddlAuto); properties.setProperty("hibernate.dialect", hibernateDialect); properties.setProperty("hibernate.show_sql", "true"); properties.setProperty("hibernate.cache.use_second_level_cache", "true"); properties.setProperty("hibernate.cache.use_query_cache" , "true");

但我收到以下错误

  • Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: 应用中使用了二级缓存,但是没有给出属性hibernate.cache.region.factory_class;请禁用二级缓存或使用 hibernate.cache.region.factory_class 设置设置正确的区域工厂,并确保二级缓存提供程序(例如 hibernate-infinispan)在类路径上可用。

为什么根据不需要的文档给出该错误。任何意见都会有所帮助。

JPA shared cache / second level cache in WildFly

谢谢 桑吉夫。

【问题讨论】:

    标签: java hibernate caching jpa


    【解决方案1】:

    你需要定义属性 hibernate.cache.region.factory_class,类似于:

    Configuration.setProperty("hibernate.cache.region.factory_class", "net.sf.ehcache.hibernate.EhCacheRegionFactory")
    

    我会使用 C3P0 或 Infinispam 作为二级缓存。

    【讨论】:

    • 我认为不必这样做。根据 Jboss Wildfly 文档。无需设置。启用 JPA 二级缓存就足够了。但这对我不起作用。 link
    • 如果您查看您发布的链接,您会发现我在上面发布的相同配置:
    【解决方案2】:

    在我的情况下,我在子项目中有不需要的 persistence.xml 文件,这使 Wildfly 变得狂野——它覆盖了配置文件。

    属性<entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/> 被完全忽略。删除(重命名)persistence.xml 后,wildfly 将使用 database.xml 中的属性重新正确启动。希望它可以节省您一些时间 (Wildfly 9.0.1Final,Hibernate 4.3.6.Final)

    【讨论】:

      猜你喜欢
      • 2015-07-05
      • 2018-09-23
      • 2017-03-31
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      • 2015-05-14
      相关资源
      最近更新 更多