1

我正在尝试将 memcached 用于 Hibernate Level 2 缓存,但还不能让它工作。当我启动 tomcat 并启动我的应用程序时,我遇到了以下异常(java.lang.NoClassDefFoundError: org/hibernate/cache/TimestampsRegion):

    javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:313)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.xxx.webapp.filter.MemberFilter.doFilter(MemberFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.xxx.webapp.filter.AuthFilter.doFilter(AuthFilter.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.xxx.webapp.filter.LanguageHandlingFilter.doFilter(LanguageHandlingFilter.java:129)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.xxx.webapp.filter.SsoFilter.doFilter(SsoFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.xxx.webapp.filter.SessionStatusFilter.doFilter(SessionStatusFilter.java:41)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.xxx.webapp.filter.BlackListFilter.doFilter(BlackListFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.xxx.webapp.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:143)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cache/TimestampsRegion
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:393)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:264)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
atorg.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)

我使用 JPA 和 hibernate 4.1.7 作为提供者。我用于休眠 L2 缓存的 persistence.xml 属性如下所示:

<property name="hibernate.cache.provider_class" value="com.googlecode.hibernate.memcached.MemcachedCacheProvider" />
        <property name="hibernate.cache.use_second_level_cache" value="true" />
        <property name="hibernate.cache.region.factory_class" value="com.googlecode.hibernate.memcached.MemcachedRegionFactory"/>
        <property name="hibernate.cache.use_query_cache" value="true" /> 
         <property name="hibernate.Memcached.servers" value="localhost:11211"/>
         <property name="hibernate.Memcached.cacheTimeSeconds" value="300"/>  

我正在使用以下与 hibernate 和 memcached 相关的 jar 文件版本:

memcached-2.3.1.jar hibernate-memcached-1.6.jar(从com.googlecode.hibernate.memcached项目的源代码编译) slf4j-1.5.0.jar slf4j-log4j12-1.5.0.jar

我还没有解决这个问题。非常感谢你们的任何帮助。

阿伦

4

2 回答 2

3

我知道这已经三年了,但这仍然非常重要。您可以在 Hibernate 4 和 5 中使用 memcached(或任何 memcache 克隆,如 elasticache)。我们自己使用 4。

您可以通过此 gradle 依赖项获取正确的 jar:

compile 'com.github.mihaicostin:hibernate-l2-memcached:1.1.0'

或 Maven: <groupId>com.github.mihaicostin</groupId> <artifactId>hibernate-l2-memcached</artifactId> <version>1.1.0</version>

它是最新的并且运行良好。在 github 上开源。 https://github.com/mihaicostin/hibernate-l2-memcached

例如,我们在 Bjond 的 persistence.xml 中的一个片段。请注意,您需要该区域工厂:

    <property name="hibernate.dialect" value="com.bjond.persistence.converter.JsonPostgreSQLDialect"/>
    <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
    <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>

     <property name="hibernate.cache.use_second_level_cache" value="true" />
     <property name="hibernate.cache.use_query_cache" value="true" />    
     <property name="hibernate.memcached.REGION.cacheTimeSeconds" value="30"/>
     <property name="hibernate.cache.region.factory_class" value="com.mc.hibernate.memcached.MemcachedRegionFactory"/>
     <property name="hibernate.memcached.operationTimeout" value="5000"/>
     <property name="hibernate.memcached.connectionFactory" value="KetamaConnectionFactory"/>
     <property name="hibernate.memcached.hashAlgorithm" value="HashAlgorithm.FNV1_64_HASH"/>
     <property name="hibernate.memcached.servers" value="localhost:11211"/>
     <property name="hibernate.memcached.cacheTimeSeconds" value="300"/>
     <property name="hibernate.memcached.clearSupported" value="false"/>
     <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
     <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/> 
     <property name="hibernate.generate_statistics" value="true" />
于 2016-06-22T12:26:30.053 回答
0

听起来您正在使用 Hibernate 4。要使用 hibernate-memcached,您应该拥有 HB3。在此处查看 hibernate-memcached 配置:https ://code.google.com/p/hibernate-memcached/wiki/Configuration

于 2013-04-11T15:48:09.753 回答