Error calling ServiceLoader.Provider.type()
j1cs opened this issue · 1 comments
Expected Behavior
I got this same error and i came up with a person in the gitter chat had the same problem. https://gitter.im/micronautfw/questions?at=628cc3224aa6c31dca197972
I thought this should be reported as a bug an find a better way to handle this in the core framework.
So taking the following setup:
plugins {
id "io.micronaut.application" version "3.3.2"
}
repositories {
mavenCentral()
}
application {
mainClass = "com.example.Application"
}
dependencies {
// micronaut-jdbc-hikari and hibernate-envers appear to collide somehow
// If you comment out one of them, the native executable runs successfully
implementation "io.micronaut:micronaut-runtime"
implementation "io.micronaut.data:micronaut-data-hibernate-jpa"
implementation "io.micronaut.sql:micronaut-jdbc-hikari"
implementation "org.hibernate:hibernate-envers:5.5.9.Final"
runtimeOnly "org.postgresql:postgresql:42.2.5"
}
graalvmNative.toolchainDetection = false
Actual Behaviour
Shows the follow error:
13:37:22.774 [main] ERROR org.hibernate.AssertionFailure - HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): java.lang.NullPointerException
13:37:22.775 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [io.micronaut.configuration.hibernate.jpa.EntityManagerFactoryBean]
Message: Error calling ServiceLoader.Provider.type()
Path Taken: new EntityManagerFactoryBean(JpaConfiguration jpaConfiguration,Integrator integrator,ApplicationContext applicationContext) --> new EntityManagerFactoryBean([JpaConfiguration jpaConfiguration],Integrator integrator,ApplicationContext applicationContext)
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [io.micronaut.configuration.hibernate.jpa.EntityManagerFactoryBean]
Message: Error calling ServiceLoader.Provider.type()
Path Taken: new EntityManagerFactoryBean(JpaConfiguration jpaConfiguration,Integrator integrator,ApplicationContext applicationContext) --> new EntityManagerFactoryBean([JpaConfiguration jpaConfiguration],Integrator integrator,ApplicationContext applicationContext)
at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1938)
at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:237)
at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:3453)
at io.micronaut.context.DefaultBeanContext.finalizeConfiguration(DefaultBeanContext.java:3883)
at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:329)
at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:183)
at io.micronaut.runtime.Micronaut.start(Micronaut.java:72)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:320)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:306)
at com.example.Application.main(Application.java:8)
Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [io.micronaut.configuration.hibernate.jpa.EntityManagerFactoryBean]
...
Caused by: org.hibernate.AssertionFailure: Error calling ServiceLoader.Provider.type()
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.collectServiceIfNotDuplicate(AggregatedServiceLoader.java:272)
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.loadAll(AggregatedServiceLoader.java:201)
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.getAll(AggregatedServiceLoader.java:187)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:251)
...
at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:132)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2336)
... 30 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.collectServiceIfNotDuplicate(AggregatedServiceLoader.java:269)...
The workaround is add @TypeHint(value = ServiceLoader.Provider.class, accessType = {TypeHint.AccessType.ALL_PUBLIC})
In my case i put it in the Application.java
class
Steps To Reproduce
No response
Environment Information
No response
Example Application
https://github.com/jachinte/micronaut-graal-envers-issue
Version
3.4.4
@n0tl3ss can you take a look, extra entries needed in https://github.com/micronaut-projects/micronaut-sql/blob/master/hibernate-jpa/src/main/java/io/micronaut/configuration/hibernate/jpa/graal/HibernateSubstitutions.java#L141 to solve this