debop / hibernate-redis

hibernate 2nd level cache privder using redis
Apache License 2.0
357 stars 181 forks source link

Hibernate 5.0.11 DefaultCacheKeysFactory - NoSuchMethodError #114

Open losingsleeep opened 6 years ago

losingsleeep commented 6 years ago

When using some versions of Spring Boot which are using Hibernate 5.0.11 by default, and specify org.hibernate.cache.redis.hibernate5.SingletonRedisRegionFactory in application properties, this run time error occurs when working with entities: java.lang.NoSuchMethodError: org.hibernate.cache.internal.DefaultCacheKeysFactory.staticCreateEntityKey(Ljava/lang/Object;Lorg/hibernate/persister/entity/EntityPersister;Lorg/hibernate/engine/spi/SessionFactoryImplementor;Ljava/lang/String;)Ljava/lang/Object; at org.hibernate.cache.redis.hibernate5.strategy.ReadWriteRedisEntityRegionAccessStrategy.generateCacheKey(ReadWriteRedisEntityRegionAccessStrategy.java:54) ~[hibernate-redis-2.4.0.jar:na] at org.hibernate.event.internal.DefaultLoadEventListener.getFromSharedCache(DefaultLoadEventListener.java:644) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:595) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:462) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.internal.SessionImpl.access$2600(SessionImpl.java:164) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2696) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.internal.SessionImpl.get(SessionImpl.java:980) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:290) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:170) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:840) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:822) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:827) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:1161) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]

If hibernate version is explicitly specified to 5.0.12 in application POM file, the problem is fixed. But It's good to be able to use this project when using Hibernate 5.0.11 for any reason.

Technical explanation: Classes inside hibernate5 package use Hibernate's class DefaultCacheKeysFactory to create cache key, but this class in version 5.0.11 is different from 5.0.12 and above. In 5.0.11 it does not have static methods which are used in this project source code.

I've changed the source code to fix it somehow, and created a pull request. Hope this helps.

Thanks to all guys starting this project and participating.

marcusleandro commented 5 years ago

I am facing the same problem with hibernate version 5.0.2.Final

losingsleeep commented 5 years ago

My pull request to fix this issue was accepted. Please check which version you're using.

losingsleeep commented 5 years ago

Here's the commit in which pull request #113 was merged:

https://github.com/debop/hibernate-redis/commit/6914b154f9989d06e4421c530ce505ca74a110c6