Open ferguardiola opened 6 years ago
same problem here
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 org.hibernate.cache.redis.hibernate52.strategy.ReadWriteRedisEntityRegionAccessStrategy.generateCacheKey(ReadWriteRedisEntityRegionAccessStrategy.java:54)
how about do it
I got the same error. Please help. hibernate 5.2.8.Final hibenrate-redis 2.3.2
The same issue has been resolved in DEVELOPMENT stream. Working fine with current 2.5.0-SNAPSHOT.
@debop When is the 2.5.0 getting released?
hibernate-redis 2.4.0 is ok
hibernate-redis 2.4.0 version can solve this issue
yes,hibernate-redis 2.4.0 is ok. Maybe you can refer to the following.
When I use the redis-Cache in NonStrictReadWrite mode, It'll throws like:
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 org.hibernate.cache.redis.hibernate52.strategy.NonStrictReadWriteRedisEntityRegionAccessStrategy.generateCacheKey(NonStrictReadWriteRedisEntityRegionAccessStrategy.java:50)
And I found the reason:
|- com.github.debop: hibernate-redis: 2.3.2 |- hibernate-redis-2.3.2.jar |- org.hibernate.cache.redis |- hibernate 52 |- strategy |- NonStrictReadWriteRedisEntityRegionAccessStrategy.java
@Override
public Object generateCacheKey(Object id,
EntityPersister persister,
SessionFactoryImplementor factory,
String tenantIdentifier) {
return DefaultCacheKeysFactory.createEntityKey(id, persister, factory, tenantIdentifier);
}
but
|- org.hibernate:hibernate-core:5.2.12.Final |- hibernate-core-5.2.12.Final.jar |- org.hibernate |- cache |- internal |- DefaultCacheKeysFactory.java
@Override
public Object createEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return staticCreateEntityKey(id, persister, factory, tenantIdentifier);
}
public static Object staticCreateEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return new CacheKeyImplementation( id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory );
}
so, it should be staticCreateEntityKey
, not createEntityKey
, or singleton should be used. And in hibernate-redis 2.4.0 it fixed:
public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return DefaultCacheKeysFactory.INSTANCE.createEntityKey(id, persister, factory, tenantIdentifier);
}
if you don't want to change the hibernate-redis 2.3.2,you can use HQL's Transformer
, that is, change the hql from :
@Override
public void update(T entity) {
getCurrentSession().update(entity);
}
to
String hql = select id as id, username as username, password as password from xxxxxx
query.setResultTransformer(CustomAliasToEntityMapResultTransformer.INSTANCE);
this way, hibernate-redis won't use the method createEntityKey
.
Another better way is change the maven pom hibernate-redis 2.3.2 to hibernate-redis 2.4.0 or higher version.but hibernate-redis 2.4.0 is not published yet, so we can download jar from https://mvnrepository.com/artifact/com.github.debop/hibernate-redis/2.4.0, and install by cmd:
mvn install:install-file -Dfile=F:/hibernate-redis-2.4.0.jar -DgroupId=com.github.debop -DartifactId=hibernate-redis -Dversion=2.4.0 -Dpackaging=jar
-DgroupId=com.extend : name of group -DartifactId=ss_css2 : name of artifact -Dversion=1.0.0 : version of jar -Dpackaging=jar : type of file
and add pom dependency(check which one you have not put in):
<dependency>
<groupId>com.github.debop</groupId>
<artifactId>hibernate-redis</artifactId>
<systemPath>${project.basedir}/libs/hibernate-redis-2.4.0.jar</systemPath>
<scope>system</scope>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.1.7</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>2.5.1</version>
</dependency>
and set the maven install plugin to copy all local jars to WEB-INF/lib
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/libs</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
<version>2.1.1</version>
</plugin>
Then it works, even the update(entity)
is ok.
Hello, When do you plan to publish version 2.4.0 ?
I got this error when reading