0

I've been using blaze-persistence CriteriaBuilder for keyset pagination in my project. This was working fine until recently when I started getting IncompatibleClassChangeError runtime exception. This happens in a couple scenarios.

On Application startup, this error is thrown when creating the createCriteriaBuilderFactory in BlazePersistenceConfiguration (stack trace shown below). Sometimes I can fix this by touching the src file, and recompilign. That allows my application to start, but any calls to access database resources via com.blazebit.persistence.CriteriaBuilder will result in the same error being thrown.

I've tried suggestions from What causes java.lang.IncompatibleClassChangeError? to no avail.

Here is the stacktrace from the error on app startup.

Caused by: java.lang.IncompatibleClassChangeError
        at com.blazebit.persistence.parser.util.JpaMetamodelUtils.resolveFieldClass(JpaMetamodelUtils.java:224)
        at com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:335)
        at com.blazebit.persistence.impl.EntityMetamodelImpl.<init>(EntityMetamodelImpl.java:127)
        at com.blazebit.persistence.impl.CriteriaBuilderFactoryImpl.<init>(CriteriaBuilderFactoryImpl.java:110)
        at com.blazebit.persistence.impl.CriteriaBuilderConfigurationImpl.createCriteriaBuilderFactory(CriteriaBuilderConfigurationImpl.java:1959)
        at oxi.configs.BlazePersistenceConfiguration.createCriteriaBuilderFactory(BlazePersistenceConfiguration.java:61)

My configuration

@Configuration
@EnableJpaRepositories(basePackages = "oxi.repository", repositoryFactoryBeanClass = BlazePersistenceRepositoryFactoryBean.class)
public class BlazePersistenceConfiguration {

    private static final Logger logger = LogManager.getLogger(BlazePersistenceConfiguration.class);

    @PersistenceUnit
    private EntityManagerFactory entityManagerFactory;

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    @Lazy(false)
    public CriteriaBuilderFactory createCriteriaBuilderFactory() {
        logger.debug("*building CriteriaBuilderFactory Bean");
        CriteriaBuilderConfiguration config = Criteria.getDefault();
        // comment
        return config.createCriteriaBuilderFactory(EntityManagerFactory);  
    }
}

build.gradle with blazebit dependencies where blazePersistenceVersion is 1.5.1 (I've also tried with 1.6.0-Alpha2):

    implementation group: 'com.blazebit', name: 'blaze-persistence-core-api', version: blazePersistenceVersion
    implementation group: 'com.blazebit', name: 'blaze-persistence-core-impl', version: blazePersistenceVersion
    implementation group: 'com.blazebit', name: 'blaze-persistence-integration-hibernate-5.4', version: blazePersistenceVersion
    implementation group: 'com.blazebit', name: 'blaze-persistence-integration-spring-data-2.1', version: blazePersistenceVersion//'1.3.2'
    implementation group: 'com.blazebit', name: 'blaze-persistence-integration-deltaspike-data', version: blazePersistenceVersion//'1.3.2'

Java Versions

Dev Machine
java version "1.8.0_25" </br>
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Server
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

Loaded jars before exception was thrown

[Loaded com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor$PathPosition from jar:file:.../WEB-INF/lib/blaze-persistence-core-parser-
1.5.1.jar!/com/blazebit/persistence/parser/PathTargetResolvingExpressionVisitor$PathPosition.class]

...

java.lang.IncompatibleClassChangeError
        at com.blazebit.persistence.parser.util.JpaMetamodelUtils.resolveFieldClass(JpaMetamodelUtils.java:224)

Attached snapshot of my WEB-INF/lib directory: enter image description here

Yoshimitsu
  • 65
  • 1
  • 9
  • Do you think you can share a sample project that shows this error or somehow show the classpath? I guess there is some old JAR on the classpath that is causing this issue. – Christian Beikov Apr 01 '21 at 07:17
  • Added an snapshot of my WEB-INF/lib directory if that's what you're looking for. I'll work on reproducing this in a sample project otherwise. – Yoshimitsu Apr 01 '21 at 22:37
  • To what kind of application server are you deploying? Are you deploying a WAR or an EAR file? – Christian Beikov Apr 02 '21 at 08:03
  • Deploying WAR on a tomcat server – Yoshimitsu Apr 02 '21 at 08:21
  • Looks like you have duplicate dependencies `jakarta.persistence` and `javax.persistence`. I guess you have to exclude one of the two. – Christian Beikov Apr 02 '21 at 10:19
  • I removed jakarta.persistence dependency, but error still persists. Trying to repro in a separate project, maybe I'll find something along the way. – Yoshimitsu Apr 05 '21 at 06:14
  • Maybe you get the `jakarta.persistence` dependency through some other transitive mechanism? The source code line as shown in the stacktrace points to the use of JPA API, so it must be related to some class loading issue. Are you using Tomcat or TomEE? I think TomEE has JPA API JARs on the classpath. – Christian Beikov Apr 06 '21 at 07:51
  • I'm running tomcat 8. I double checked my gradle dependencies and did not find jakarta.persistence present. Also checked my catalina.out logs and did not find any reference to jakarta.persistence being loaded during startup. – Yoshimitsu Apr 07 '21 at 09:42
  • That's really odd. Looking forward to a reproducer to analyze this further! – Christian Beikov Apr 07 '21 at 10:22

0 Answers0