Code Monkey home page Code Monkey logo

hibernate-l2-memcached's Introduction

Hibernate - Memcached

A library for using Memcached as a second level distributed cache in Hibernate.

  • Uses spymemcached client
  • Supports entity and query caching.

Java CI with Maven

Jump to

Maven dependency

To install it, you just need to add the following Maven dependency (check Versions for the right version for you):

<dependency>
    <groupId>com.github.mihaicostin</groupId>
    <artifactId>hibernate-l2-memcached</artifactId>
    <version>5.4.2.1</version>
</dependency>

https://mvnrepository.com/artifact/com.github.mihaicostin/hibernate-l2-memcached

Example config:

<property name="hibernate.cache.region.factory_class">com.mc.hibernate.memcached.MemcachedRegionFactory</property>
<property name="hibernate.memcached.operationTimeout">5000</property>
<property name="hibernate.memcached.connectionFactory">KetamaConnectionFactory</property>
<property name="hibernate.memcached.hashAlgorithm">FNV1_64_HASH</property>

If memcached authentication is required you can specify username and password:

<property name="hibernate.memcached.username">memcached-username</property>
<property name="hibernate.memcached.password">memcached-password</property>

If memcached are running on a remote server, e.g. on AWS ElastiCache, you can specify the connection URL:

<property name="hibernate.memcached.servers">cache.c3wd5k.cfg.euw1.cache.amazonaws.com:11211</property>

Configuration options

Targeting the memcached client (net.spy.memcached configurations)

Property Default Value
hibernate.memcached.servers localhost:11211
hibernate.memcached.operationQueueLength (default provided by net.spy.memcached.DefaultConnectionFactory)
hibernate.memcached.readBufferSize (default provided by net.spy.memcached.DefaultConnectionFactory)
hibernate.memcached.operationTimeout (default provided by net.spy.memcached.DefaultConnectionFactory)
hibernate.memcached.hashAlgorithm NATIVE_HASH
hibernate.memcached.connectionFactory DefaultConnectionFactory
hibernate.memcached.daemonMode false
hibernate.memcached.username -
hibernate.memcached.password -

Targeting the cache implementation (global or region specific)

Property Default Value
hibernate.memcached.cacheTimeSeconds 300
hibernate.memcached.clearSupported false
hibernate.memcached.memcacheClientFactory com.mc.hibernate.memcached.spymemcached.SpyMemcacheClientFactory
hibernate.memcached.dogpilePrevention false
hibernate.memcached.dogpilePrevention.expirationFactor 2
hibernate.memcached.keyStrategy com.mc.hibernate.memcached.keystrategy.Sha1KeyStrategy

In order to specify a property for a specific region add the region name right after memcached. ex: hibernate.memcached.myregion.cacheTimeSeconds

Versions

Use the version compatible with your hibernate version (ex: Version 5.2.1.x is developed for and compatible with hibernate 5.2.1.Final)

Hibernate 6.2.x

  • v 6.2.1.0
    • Added support for Hibernate 6.2.1.Final (PR by @wglasshusain). Note: This version requires Java 17

Hibernate 5.4.x

Hibernate 5.3.x

  • no support for hibernate 5.3.0 - 5.3.2
  • for hibernate 5.3.3 - 5.3.9 use v 5.4.2.0

Hibernate 5.2.x

  • v 5.2.17.0
    • Fix for Issue #16
    • hibernate-core dependency (as provided): 5.2.17.Final
  • v 5.2.10.0
    • Add a new cache property hibernate.memcached.cacheLockTimeout (defaults to 60.000 ms)
    • Update to latest spymemcached version
    • hibernate-core dependency (as provided): 5.2.10.Final
  • v 5.2.7.1
  • v 5.2.7.0
    • Support Hibernate 5.2.7.Final (PR by @akhalikov )
    • Update spymemcached to 2.12.2
    • Tested with 5.2.7.Final - 5.2.10.Final
  • v 5.2.1.0

Hibernate 5.1.x

  • v 5.1.5.1
  • v 5.1.5.0
    • Support for Hibernate 5.1.x (tested with 5.1.1.Final - 5.1.5.Final)

Hibernate 5.0.x

  • v 5.0.1.0
    • Support for Hibernate 5.0.x

Hibernate 4.3.x

  • v 4.3.11.0
    • Fix for Issue #9 (configure the cache with all available properties)
  • v 1.1.0
    • Memcached client now respects the region timeout property Issue #1
      <property name="hibernate.memcached.REGION.cacheTimeSeconds">10</property>
  • v 1.0.0
    • Compatible with hibernate 4.3.x

Known issues

Acknowledgements

hibernate-l2-memcached's People

Contributors

andrescmasmas avatar dependabot[bot] avatar larshelge avatar mihaicostin avatar snyk-bot avatar vladmihalcea avatar wglasshusain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hibernate-l2-memcached's Issues

Exception when using hibernate-l2-memcached with JPA Hibernate on Jboss EAP 7

Hello,

Trying to use hibernate-l2-memcached with JPA Hibernate (I guess 5.0.1) on Jboss EAP 7, with a localhost memcached server.

I follow instructions regarding the configuration but when my app try to get an Entity, I have this exception:
java.lang.NoSuchFieldError: INSTANCE
at com.mc.hibernate.memcached.strategy.ReadWriteMemcachedEntityRegionAccessStrategy.generateCacheKey(ReadWriteMemcachedEntityRegionAccessStrategy.java:113)

My persistence.xml





java:jboss/datasources/Hibernate5QuickstartDS
ENABLE_SELECTIVE












The Server.log:

12:01:45,073 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,077 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,077 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0006: Starting Services for CDI deployment: jboss-hibernate5.war
12:01:45,082 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,085 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,127 INFO [org.jboss.weld.Version] (MSC service thread 1-1) WELD-000900: 2.3.1 (redhat)
12:01:45,193 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0009: Starting weld service for deployment jboss-hibernate5.war
12:01:45,431 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 66) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'jboss-hibernate5.war#primary'
12:01:45,540 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 65) WFLYCLINF0002: Started client-mappings cache from ejb container
12:01:45,867 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 66) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
12:01:45,917 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 66) Envers integration enabled? : true
12:01:46,192 INFO [com.mc.hibernate.memcached.MemcachedRegionFactory] (ServerService Thread Pool -- 66) Starting MemcachedClient...
12:01:46,228 ERROR [stderr] (ServerService Thread Pool -- 66) 2017-02-14 12:01:46.227 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0
, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
12:01:46,236 INFO [org.hibernate.cache.spi.UpdateTimestampsCache] (ServerService Thread Pool -- 66) HHH000250: Starting update timestamps cache at region: jboss-hibernate5.war#primary.or
g.hibernate.cache.spi.UpdateTimestampsCache
12:01:46,242 INFO [org.hibernate.cache.internal.StandardQueryCache] (ServerService Thread Pool -- 66) HHH000248: Starting query cache at region: jboss-hibernate5.war#primary.org.hibernat
e.cache.internal.StandardQueryCache
12:01:46,457 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 66) HHH000227: Running hbm2ddl schema export
12:03:25,990 INFO [stdout] (default task-1) Hibernate: select this_.id as id1_0_0_, this_.address as address2_0_0_, this_.email as email3_0_0_, this_.name as name4_0_0_, this_.phone_numb
er as phone_nu5_0_0_ from MemberHibernateDemo this_ order by this_.name asc
12:03:26,034 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-1) Error Rendering View[/index.xhtml]: org.jboss.weld.exceptions.WeldException: WELD-000049: Una
ble to invoke public void org.jboss.as.quickstart.hibernate.data.MemberListProducer.retrieveAllMembersOrderedByName() on org.jboss.as.quickstart.hibernate.data.MemberListProducer@5e9f318e

    at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:100)
    at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81)
    at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:126)
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:162)
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
    at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
    at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:178)
    at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)
    at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:123)
    at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:158)
    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:181)
    at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:70)
    at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
    at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)
    at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:120)
    at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
    at org.jboss.as.jsf.injection.weld.ForwardingELResolver.getValue(ForwardingELResolver.java:46)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
    at com.sun.el.parser.AstEmpty.getValue(AstEmpty.java:66)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:458)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98)
... 67 more
Caused by: java.lang.NoSuchFieldError: INSTANCE
at com.mc.hibernate.memcached.strategy.ReadWriteMemcachedEntityRegionAccessStrategy.generateCacheKey(ReadWriteMemcachedEntityRegionAccessStrategy.java:113)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:187)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:128)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1132)
at org.hibernate.loader.Loader.processResultSet(Loader.java:992)
at org.hibernate.loader.Loader.doQuery(Loader.java:930)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2611)
at org.hibernate.loader.Loader.doList(Loader.java:2594)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2423)
at org.hibernate.loader.Loader.list(Loader.java:2418)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1705)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at org.jboss.as.quickstart.hibernate.data.MemberRepository.findAllOrderedByName(MemberRepository.java:48)
at org.jboss.as.quickstart.hibernate.data.MemberRepository$Proxy$_$$_WeldClientProxy.findAllOrderedByName(Unknown Source)
at org.jboss.as.quickstart.hibernate.data.MemberListProducer.retrieveAllMembersOrderedByName(MemberListProducer.java:66)
... 72 more

Memcached server : memcached-win64-1.4.4-14
Jboss EAP 7/ Hibernate 5.0.1
hibernate-l2-memcached: 5.2.7.0

Hello,

Trying to use hibernate-l2-memcached with JPA Hibernate (I guess 5.0.1) on Jboss EAP 7, with a localhost memcached server

I follow instructions regarding the configuration but when my app try to get an Entity, I have this exception:
java.lang.NoSuchFieldError: INSTANCE
at com.mc.hibernate.memcached.strategy.ReadWriteMemcachedEntityRegionAccessStrategy.generateCacheKey(ReadWriteMemcachedEntityRegionAccessStrategy.java:113)

My persistence.xml





java:jboss/datasources/Hibernate5QuickstartDS
ENABLE_SELECTIVE












The Server.log:

12:01:45,073 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,077 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,077 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0006: Starting Services for CDI deployment: jboss-hibernate5.war
12:01:45,082 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,085 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being
selected. Only manually evicted entities will be passivated.
12:01:45,127 INFO [org.jboss.weld.Version] (MSC service thread 1-1) WELD-000900: 2.3.1 (redhat)
12:01:45,193 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0009: Starting weld service for deployment jboss-hibernate5.war
12:01:45,431 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 66) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'jboss-hibernate5.war#primary'
12:01:45,540 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 65) WFLYCLINF0002: Started client-mappings cache from ejb container
12:01:45,867 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 66) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
12:01:45,917 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 66) Envers integration enabled? : true
12:01:46,192 INFO [com.mc.hibernate.memcached.MemcachedRegionFactory] (ServerService Thread Pool -- 66) Starting MemcachedClient...
12:01:46,228 ERROR [stderr] (ServerService Thread Pool -- 66) 2017-02-14 12:01:46.227 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0
, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
12:01:46,236 INFO [org.hibernate.cache.spi.UpdateTimestampsCache] (ServerService Thread Pool -- 66) HHH000250: Starting update timestamps cache at region: jboss-hibernate5.war#primary.or
g.hibernate.cache.spi.UpdateTimestampsCache
12:01:46,242 INFO [org.hibernate.cache.internal.StandardQueryCache] (ServerService Thread Pool -- 66) HHH000248: Starting query cache at region: jboss-hibernate5.war#primary.org.hibernat
e.cache.internal.StandardQueryCache
12:01:46,457 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 66) HHH000227: Running hbm2ddl schema export
12:03:25,990 INFO [stdout] (default task-1) Hibernate: select this_.id as id1_0_0_, this_.address as address2_0_0_, this_.email as email3_0_0_, this_.name as name4_0_0_, this_.phone_numb
er as phone_nu5_0_0_ from MemberHibernateDemo this_ order by this_.name asc
12:03:26,034 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-1) Error Rendering View[/index.xhtml]: org.jboss.weld.exceptions.WeldException: WELD-000049: Una
ble to invoke public void org.jboss.as.quickstart.hibernate.data.MemberListProducer.retrieveAllMembersOrderedByName() on org.jboss.as.quickstart.hibernate.data.MemberListProducer@5e9f318e

    at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:100)
    at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81)
    at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:126)
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:162)
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
    at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
    at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:178)
    at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)
    at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:123)
    at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:158)
    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:181)
    at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:70)
    at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
    at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)
    at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:120)
    at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
    at org.jboss.as.jsf.injection.weld.ForwardingELResolver.getValue(ForwardingELResolver.java:46)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
    at com.sun.el.parser.AstEmpty.getValue(AstEmpty.java:66)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:458)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98)
... 67 more
Caused by: java.lang.NoSuchFieldError: INSTANCE
at com.mc.hibernate.memcached.strategy.ReadWriteMemcachedEntityRegionAccessStrategy.generateCacheKey(ReadWriteMemcachedEntityRegionAccessStrategy.java:113)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:187)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:128)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1132)
at org.hibernate.loader.Loader.processResultSet(Loader.java:992)
at org.hibernate.loader.Loader.doQuery(Loader.java:930)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2611)
at org.hibernate.loader.Loader.doList(Loader.java:2594)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2423)
at org.hibernate.loader.Loader.list(Loader.java:2418)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1705)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at org.jboss.as.quickstart.hibernate.data.MemberRepository.findAllOrderedByName(MemberRepository.java:48)
at org.jboss.as.quickstart.hibernate.data.MemberRepository$Proxy$_$$_WeldClientProxy.findAllOrderedByName(Unknown Source)
at org.jboss.as.quickstart.hibernate.data.MemberListProducer.retrieveAllMembersOrderedByName(MemberListProducer.java:66)
... 72 more

Memcached server : memcached-win64-1.4.4-14
Jboss EAP 7/ Hibernate 5.0.1
hibernate-l2-memcached: 5.2.7.0

A soft-locked cache entry was expired by the underlying Memcache

Hi,

I have been seeing this on logs A soft-locked cache entry was expired by the underlying Memcache
This happens when I try to update and during that if there's any exception caused, The transaction is rolled back. During the transaction rollback I'm seeing this. When there's a successful update. I don't see this. Basically my understanding was when there's a
successful update
{lockItem} -> {update} -> {afterUpdate} and in afterUpdate it unlocks
But during a rollback
It directly goes to afterUpdate and tries to unlock without a lock. And so it's printing that warning.

Could you please let me know what's the best approach I can do here.

Thanks

Cache eviction problem on Hibernate 4.3

This appears similar to #9 but I have no easy way to verify the "eviction" is occurring.

Hibernate: 4.3.9.Final (and 4.3.11.Final, same results)
Hibernate-l2-memcached: 4.3.11.0

I am attempting to switch from ehcache to memcached and am running into issues which appear to be eviction-related. I can verify that the problem occurs only when using memcached as the second-level cache.

In my code, I have a flushAndClear function which I am calling in my integration tests.

  protected void flushAndClear() {
    sessionFactory.getCurrentSession().flush();
    sessionFactory.getCurrentSession().clear();
    sessionFactory.getCache().evictAllRegions();
  }

Configuration

hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: true
hibernate.cache.use_structured_entries: true
# hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
hibernate.cache.region.factory_class: com.mc.hibernate.memcached.MemcachedRegionFactory
hibernate.memcached.cacheTimeSeconds: 60
hibernate.memcached.clearSupported: true

I am running the above flushAndClear between making an update and querying it from the cache. The test is returning the pre-cache value.

Cache eviction problem

It appears that cache eviction is not working properly. Versions:

Hibernate: 5.1.5.Final
Hibernate-l2-memcached: 5.1.5.0

In our app we are relying on clearing / evicting the second level cache. The code looks like this:

sessionFactory.getCache().evictEntityRegions();
sessionFactory.getCache().evictCollectionRegions();
sessionFactory.getCache().evictDefaultQueryRegion();
sessionFactory.getCache().evictQueryRegions();

This works when ehcache is used as cache provider. However, this code appears to have no effect when using hibernate-l2-memcached as cache provider.

Evidence 1

  • We load a web page twice, and verify from database logs (Postgres) that no queries hit the database after first page load.
  • Clear second level cache using the function described above.
  • Load the same web page again. This time, still no queries hit the database. Verified that this works with ehcache.

Evidence 2

  • We load a web page.
  • Inspect memcached server instance running on localhost by listing all keys and values (we get 5629 entries).
  • Clear second level cache using the function described above.
  • Inspect memcached server instance again. This time we still get the exact same number of cache entries.

Conclusion

It appears that hibernate-l2-memcached is not implementing the programmatic cache eviction contract properly based on these observations.

Hibernate 5.1 series support

Are there any plans for support Hibernate 5.1 series?

We are on Hibernate version 5.1.5. When using hibernate-l2-memcached version 5.0.1.0 we get this exception during startup:

Caused by: java.lang.IncompatibleClassChangeError: Expected static method org.hibernate.cache.internal.DefaultCacheKeysFactory.createEntityKey(Ljava/lang/Object;Lorg/hibernate/persister/entity/EntityPersister;Lorg/hibernate/engine/spi/SessionFactoryI at com.mc.hibernate.memcached.strategy.ReadWriteMemcachedEntityRegionAccessStrategy.generateCacheKey(ReadWriteMemcachedEntityRegionAccessStrategy.java:113) at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:184) at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1139) at org.hibernate.loader.Loader.processResultSet(Loader.java:998) at org.hibernate.loader.Loader.doQuery(Loader.java:936) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342) at org.hibernate.loader.Loader.doList(Loader.java:2622) at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2464) at org.hibernate.loader.Loader.list(Loader.java:2426) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:385)

When using hibernate-l2-memcached version 5.2.1.0 we get this exception during startup:

Caused by: java.lang.AbstractMethodError: com.mc.hibernate.memcached.region.MemcachedQueryResultsRegion.get(Lorg/hibernate/engine/spi/SessionImplementor;Ljava/lang/Object;)Ljava/lang/Object; at org.hibernate.cache.internal.StandardQueryCache.getCachedResults(StandardQueryCache.java:242) at org.hibernate.cache.internal.StandardQueryCache.get(StandardQueryCache.java:158) at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2546) at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2454) at org.hibernate.loader.Loader.list(Loader.java:2426) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:385)

Would support for Hibernate 5.1 be feasible to implement?

NonStrictReadWriteMemcachedCollectionRegionAccessStrategy.get(SharedSessionContractImplementor, Object, long) returns null

In latest version we have NonStrictReadWriteMemcachedCollectionRegionAccessStrategy class that implements Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException; method from 'RegionAccessStrategy' but actually returns null. This change was introduced as part of commit b251ea4309f437038de032385e04457ef553d31c.

This makes cached entities with eagerly fetched collections that use CacheConcurrencyStrategy.NONSTRICT_READ_WRITE to get reloaded again from database when they are actually cached.

Hibernate 5.3.x support

Hi,

Do you have plans to support Hibernate 5.3.x and if so when can we expect that support to be available? We currently use hibernate-l2-memcached with Hibernate 5.2.x and an Elasticache backend in AWS and are unable to upgrade to Hibernate 5.3.x without a hibernate-l2-memcached to support it. I appreciate that is probably no trivial matter following the significant changes in the caching SPI that came in Hibernate 5.3.

Best regards,
Gareth

Cache Time is configured in seconds while nextTimestamp returns deciseconds

In class MemcachedCache the two methods:

    public long nextTimestamp() {
        return System.currentTimeMillis() / 100;
    }

    public int getTimeout() {
        return cacheTimeSeconds;
    }

return inconsistent time units. This creates wrong calculations, see hibernates UpdateTiemstampsCache#preInvalidate:

		final Long ts = region.nextTimestamp() + region.getTimeout();

adding seconds to deciseconds.

I guess the / 100 should just be / 1000 ?

See this for reference: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/regions/EhcacheDataRegion.java#L61

Region specific settings (cacheTimeSeconds) are not applied

The MemcachedCache class which represents a region doesn't read the region specific configuration.

For example, if you configure (yaml syntax):

hibernate:
    cache:
        memcached:
            operationTimeout: 700 #700ms
            # Specific per region
            com.bla.product.ClassName.cacheTimeSeconds: 300 # 5min

Then operationTimeout will be applied as intended but the cacheTimeSeconds for the "com.bla.product.ClassName" region is not applied.

StrategySelectionException: Unable to resolve name [com.mc.hibernate.memcached.MemcachedRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory]

I am trying to integrate this with Spring + Hibernate

Please help

<beans:prop key="hibernate.cache.use_query_cache">true</beans:prop> <beans:prop key="hibernate.cache.use_second_level_cache">true</beans:prop> <beans:prop key="hibernate.cache.use_structured_entries">true</beans:prop> <beans:prop key="hibernate.cache.configurationResourceName"></beans:prop> <beans:prop key="hibernate.generate_statistics">true</beans:prop> <beans:prop key="hibernate.memcached.operationTimeout">60000</beans:prop> <beans:prop key="hibernate.memcached.connectionFactory">KetamaConnectionFactory</beans:prop> <beans:prop key="hibernate.memcached.hashAlgorithm">HashAlgorithm.FNV1_64_HASH</beans:prop> <beans:prop key="hibernate.memcached.REGION.cacheTimeSeconds">86400000</beans:prop> <beans:prop key="hibernate.memcached.servers">localhost:11211</beans:prop> <beans:prop key="hibernate.memcached.cacheTimeSeconds">86400000</beans:prop> <beans:prop key="hibernate.memcached.clearSupported">false</beans:prop> <beans:prop key="hibernate.cache.region.factory_class">com.mc.hibernate.memcached.MemcachedRegionFactory</beans:prop>

Build for Hibernate 5.0.12.0

Hi,

I've been checking that the last build available on MVN Central (5.0.1.0) it'is not compatible with Hibernate 5.0.12.0, could you please send the build of branch hibernate-5.0.1 that is already updated to Hibernate 5.0.12.0 to the central?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.