Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IncompatibleClassChangeError: Expected static method org.hibernate.cache.internal.DefaultCacheKeysFactory.createEntityKey #115

Open
ferguardiola opened this issue Mar 8, 2018 · 8 comments

Comments

@ferguardiola
Copy link

I got this error when reading


ERROR [2018-03-08 16:24:49,046] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: b115cc414749df4f
! 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)
! at org.hibernate.event.internal.DefaultLoadEventListener.getFromSharedCache(DefaultLoadEventListener.java:644)
! at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:595)
! at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:462)
! at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)
! at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278)
! at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121)
! at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)
! at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239)
! at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)
! at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:646)
! at org.hibernate.type.EntityType.resolve(EntityType.java:431)
! at org.hibernate.type.ComponentType.resolve(ComponentType.java:688)
! at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:192)
! at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2854)
! at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1747)
! at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1673)
! at org.hibernate.loader.Loader.getRow(Loader.java:1562)
! at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:732)
! at org.hibernate.loader.Loader.processResultSet(Loader.java:991)
! at org.hibernate.loader.Loader.doQuery(Loader.java:949)
! at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
! at org.hibernate.loader.Loader.doList(Loader.java:2692)
! at org.hibernate.loader.Loader.doList(Loader.java:2675)
! at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507)
! at org.hibernate.loader.Loader.list(Loader.java:2502)
! at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502)
! at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:384)
! at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
! at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490)
! at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445)
! at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
! at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1463)
! at net.axisdata.ub2b.app.dao.contract.ContractDAO.getById(ContractDAO.java:22)
! at net.axisdata.ub2b.app.services.impl.ContractServiceImpl.getContract(ContractServiceImpl.java:22)
! at net.axisdata.ub2b.app.resource.DataResource.getContracts(DataResource.java:198)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)
! at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
! at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
! at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
! at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)

This is my configuration

<dependency>
       <groupId>com.github.debop</groupId>
        <artifactId>hibernate-redis</artifactId>
        <version>2.3.2</version>
 </dependency>
 <dependency>
        <groupId>org.redisson</groupId>
        <artifactId>redisson</artifactId>
        <version>2.11.2</version>
 </dependency>

Hibernate: 5.2.12.Final

Working with droprwizard 1.2.2


What is wrong ?

@raphaelLacerda
Copy link

raphaelLacerda commented Apr 19, 2018

same problem here

org.hibernate hibernate-core 5.2.16.Final com.github.debop hibernate-redis 2.3.2

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)

@leihfei
Copy link

leihfei commented Apr 25, 2018

how about do it

@debashishbharali
Copy link

I got the same error. Please help.
hibernate 5.2.8.Final
hibenrate-redis 2.3.2

@debashishbharali
Copy link

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?

@andyrenkehe
Copy link

hibernate-redis 2.4.0 is ok

@jingcoder
Copy link

hibernate-redis 2.4.0 version can solve this issue

@BEWINDOWEB
Copy link

BEWINDOWEB commented Dec 7, 2018

yes,hibernate-redis 2.4.0 is ok. Maybe you can refer to the following.

issue

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)

Reason

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);
    }

How to resolve the problem

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.

@anthonyrichir
Copy link

Hello,
When do you plan to publish version 2.4.0 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants