question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hibernate integration 5.3 and 5.4 is not working in a modular application

See original GitHub issue

Description

Blaze Persistence cannot initialize in modularized mode

Actual behavior

The following exception is thrown:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'advisorService' defined in file [/home/zalavaari/drasyl/tpm2/be/service/target/classes/com/drasyl/tpm/service/advisor/AdvisorService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tpmqlService' defined in file [/home/zalavaari/drasyl/tpm2/be/service/target/classes/com/drasyl/tpm/service/tpmql/TpmqlService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createCriteriaBuilderFactory' defined in class path resource [com/drasyl/tpm/spring/database/ConfigureBlazePersistence.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.CriteriaBuilderFactory]: Factory method 'createCriteriaBuilderFactory' threw exception; nested exception is java.lang.NullPointerException
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.context@5.2.7.RELEASE/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.7.RELEASE.jar:na]
	at spring.context@5.2.7.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.7.RELEASE.jar:na]
	at spring.boot@2.3.1.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.1.RELEASE.jar:na]
	at spring.boot@2.3.1.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.1.RELEASE.jar:na]
	at spring.boot@2.3.1.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.1.RELEASE.jar:na]
	at spring.boot@2.3.1.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.1.RELEASE.jar:na]
	at spring.boot@2.3.1.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.1.RELEASE.jar:na]
	at spring.boot@2.3.1.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.1.RELEASE.jar:na]
	at spring.boot@2.3.1.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.1.RELEASE.jar:na]
	at com.drasyl.tpm.standalone/com.drasyl.tpm.standalone.Main.main(Main.java:43) ~[classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tpmqlService' defined in file [/home/zalavaari/drasyl/tpm2/be/service/target/classes/com/drasyl/tpm/service/tpmql/TpmqlService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createCriteriaBuilderFactory' defined in class path resource [com/drasyl/tpm/spring/database/ConfigureBlazePersistence.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.CriteriaBuilderFactory]: Factory method 'createCriteriaBuilderFactory' threw exception; nested exception is java.lang.NullPointerException
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1304) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1224) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.7.RELEASE.jar:na]
	... 20 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createCriteriaBuilderFactory' defined in class path resource [com/drasyl/tpm/spring/database/ConfigureBlazePersistence.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.CriteriaBuilderFactory]: Factory method 'createCriteriaBuilderFactory' threw exception; nested exception is java.lang.NullPointerException
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1304) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1224) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.7.RELEASE.jar:na]
	... 34 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.CriteriaBuilderFactory]: Factory method 'createCriteriaBuilderFactory' threw exception; nested exception is java.lang.NullPointerException
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.7.RELEASE.jar:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.7.RELEASE.jar:na]
	... 48 common frames omitted
Caused by: java.lang.NullPointerException: null
	at com.blazebit.persistence.integration.hibernate.base@1.4.1/com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.getColumnTypes(HibernateJpaProvider.java:915) ~[blaze-persistence-integration-hibernate-base-1.4.1.jar:na]
	at com.blazebit.persistence.core.impl@1.4.1/com.blazebit.persistence.impl.EntityMetamodelImpl$AttributeEntry.<init>(EntityMetamodelImpl.java:1054) ~[blaze-persistence-core-impl-1.4.1.jar:na]
	at com.blazebit.persistence.core.impl@1.4.1/com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:406) ~[blaze-persistence-core-impl-1.4.1.jar:na]
	at com.blazebit.persistence.core.impl@1.4.1/com.blazebit.persistence.impl.EntityMetamodelImpl.<init>(EntityMetamodelImpl.java:125) ~[blaze-persistence-core-impl-1.4.1.jar:na]
	at com.blazebit.persistence.core.impl@1.4.1/com.blazebit.persistence.impl.CriteriaBuilderFactoryImpl.<init>(CriteriaBuilderFactoryImpl.java:107) ~[blaze-persistence-core-impl-1.4.1.jar:na]
	at com.blazebit.persistence.core.impl@1.4.1/com.blazebit.persistence.impl.CriteriaBuilderConfigurationImpl.createCriteriaBuilderFactory(CriteriaBuilderConfigurationImpl.java:1668) ~[blaze-persistence-core-impl-1.4.1.jar:na]
	at com.drasyl.tpm.spring/com.drasyl.tpm.spring.database.ConfigureBlazePersistence.createCriteriaBuilderFactory(ConfigureBlazePersistence.java:26) ~[classes/:na]
	at com.drasyl.tpm.spring/com.drasyl.tpm.spring.database.ConfigureBlazePersistence$$EnhancerBySpringCGLIB$$2c564d5c.CGLIB$createCriteriaBuilderFactory$0(<generated>) ~[classes/:na]
	at com.drasyl.tpm.spring/com.drasyl.tpm.spring.database.ConfigureBlazePersistence$$EnhancerBySpringCGLIB$$2c564d5c$$FastClassBySpringCGLIB$$45413863.invoke(<generated>) ~[classes/:na]
	at spring.core@5.2.7.RELEASE/org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.7.RELEASE.jar:na]
	at spring.context@5.2.7.RELEASE/org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.2.7.RELEASE.jar:na]
	at com.drasyl.tpm.spring/com.drasyl.tpm.spring.database.ConfigureBlazePersistence$$EnhancerBySpringCGLIB$$2c564d5c.createCriteriaBuilderFactory(<generated>) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at spring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.7.RELEASE.jar:na]
	... 49 common frames omitted

Environment

Spring Boot 2.3.1 Spring 5.2.7 Hibernate 5.4.17 Blaze 1.4.1

The root of the problem

The HibernateJpaProvider instance cannot find the Database service. There is no Database service, because Hibernate53Integrator and Hibernate53ServiceContributor is not provided correctly by the integrator module.

The solution

The Hibernate53Integrator is alredy defined in the module-info, but it has an error. The current line is: provides org.hibernate.integrator.spi.ServiceContributingIntegrator with com.blazebit.persistence.integration.hibernate.Hibernate53Integrator; The problem with this, is that Hibernate53Integrator does not implement ServiceContributingIntegrator interface, just the Integrator. So the definition should be the following: provides org.hibernate.integrator.spi.Integrator with com.blazebit.persistence.integration.hibernate.Hibernate53Integrator;

The Hibernate53ServiceContributor’s definition is completely missing from the module-info: provides org.hibernate.service.spi.ServiceContributor with com.blazebit.persistence.integration.hibernate.Hibernate53ServiceContributor;

(For initializing Hibernate53EntityManagerFactoryIntegrator, the package com.blazebit.persistence.integration.hibernate.base.function should be also exported from the com.blazebit.persistence.integration.hibernate.base module)

So I think this is a working definition of the integration module (for both Hibernate 5.3 and 5.4):

module ${module.name} {
    requires java.sql;
    requires java.persistence;
    requires org.hibernate.orm.core;
    requires com.blazebit.persistence.core;
    requires com.blazebit.persistence.integration.hibernate.base;
    provides org.hibernate.integrator.spi.Integrator with com.blazebit.persistence.integration.hibernate.Hibernate53Integrator;
    provides com.blazebit.persistence.integration.hibernate.base.HibernateAccess with com.blazebit.persistence.integration.hibernate.Hibernate53Access;
    provides com.blazebit.persistence.spi.EntityManagerFactoryIntegrator with com.blazebit.persistence.integration.hibernate.Hibernate53EntityManagerFactoryIntegrator;
    provides org.hibernate.service.spi.ServiceContributor with com.blazebit.persistence.integration.hibernate.Hibernate53ServiceContributor;
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zalavaaricommented, Jun 19, 2020

@jwgmeligmeyling

Yes, it’s possible. It’s pure beauty. 😃

I’ve tested and modified it slightly:

  Method getModule = Class.class.getDeclaredMethod("getModule");
  Object module = getModule.invoke(Version.class);
  Method getDescriptor = module.getClass().getDeclaredMethod("getDescriptor");
  Object descriptor = getDescriptor.invoke(module);
  Method versionGetter = descriptor.getClass().getDeclaredMethod("version");
  Optional<Object> versionOptional = (Optional<Object>) versionGetter.invoke(descriptor);
  version = String.valueOf(versionOptional.get());

(The version() method returns with a Optional<ModuleDescriptor.Version>)

0reactions
beikovcommented, Jun 19, 2020

Glad to hear that. Could you maybe give us some details about what you are doing with Blaze-Persistence in a modularized app. We are curious 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Working with both Object-Oriented software and Relational Databases can be cumbersome and time-consuming. Development costs are significantly higher due to ...
Read more >
An example hibernate.cfg.xml for MySQL 8 and Hibernate 5
Here's an example hibernate.cfg.xml for MySQL 8 for Hibernate 5 apps or ... of applications in production that use the Hibernate framework ...
Read more >
Bootstrapping Hibernate 5 with Spring - Baeldung
A quick and practical guide to integrating Hibernate 5 with Spring ... The spring-orm module provides the Spring integration with Hibernate:
Read more >
Spring MVC + Hibernate XML Based Configuration Example
To integrate Hibernate with the Spring MVC application, you can use the LocalSessionFactoryBean class, which setup a shared SessionFactory object within a ...
Read more >
Using jpa2.2 on Websphere with spring/hibernate
The problem is, the link says to use persistence.xml ; but the application I've inherited doesn't have that xml file. It only has ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found