title: Hibernate L2 caching using memcached
body: <p>I am trying to use memcached for Hibernate Level 2 caching but haven't been able to get it working yet. I am running into the following exception(java.lang.NoClassDefFoundError: org/hibernate/cache/TimestampsRegion) when I fire up the tomcat and launch my application :</p>
  
  <pre><code>    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.&lt;init&gt;(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)
  </code></pre>
  
  <p>I am using JPA with hibernate 4.1.7 as the provider. My persistence.xml properties for hibernate L2 caching look like :</p>
  
  <pre><code>&lt;property name="hibernate.cache.provider_class" value="com.googlecode.hibernate.memcached.MemcachedCacheProvider" /&gt;
          &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
          &lt;property name="hibernate.cache.region.factory_class" value="com.googlecode.hibernate.memcached.MemcachedRegionFactory"/&gt;
          &lt;property name="hibernate.cache.use_query_cache" value="true" /&gt; 
           &lt;property name="hibernate.Memcached.servers" value="localhost:11211"/&gt;
           &lt;property name="hibernate.Memcached.cacheTimeSeconds" value="300"/&gt;  
  </code></pre>
  
  <p>I am using following versions of jar files related to hibernate and memcached :</p>
  
  <p>memcached-2.3.1.jar
  hibernate-memcached-1.6.jar (compiled from the source from com.googlecode.hibernate.memcached project)
  slf4j-1.5.0.jar
  slf4j-log4j12-1.5.0.jar</p>
  
  <p>I haven't been able to get around this problem yet. Any help from you guys is greatly appreciated.</p>
  
  <p>Arun</p>