Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Error creating bean with name 'entityManagerFactory' #1668

Closed
fragaLY opened this issue Jul 11, 2022 · 9 comments
Closed

Error creating bean with name 'entityManagerFactory' #1668

fragaLY opened this issue Jul 11, 2022 · 9 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@fragaLY
Copy link

fragaLY commented Jul 11, 2022

Hello, pioneers,

I would like to find a way of solving the problem regarding the entity manager initialization.

The sample of the project is here: https://github.com/fragaLY/performance-researches/tree/master/spring-boot-web-native

  1. To be ready to start it up please run the docker-compose up in the /docker directory to boot up the database.
  2. After that execute ./gradlew nativeCompile
  3. Run built artifact.

The actual result is:

2022-07-11 16:37:59.475 INFO 96854 --- [ main] o.s.nativex.NativeListener : AOT mode enabled
2022-07-11 16:37:59.481 INFO 96854 --- [ main] b.v.s.SpringBootWebNativeApplication : Starting SpringBootWebNativeApplication using Java 17.0.3 on MACHINE with PID 96854 (/Users/Vadzim_Kavalkou/IdeaProjects/common/performance-researches/spring-boot-web-native/build/native/nativeCompile/spring-boot-web-native started by Vadzim_Kavalkou in /Users/Vadzim_Kavalkou/IdeaProjects/common/performance-researches/spring-boot-web-native/build/native/nativeCompile)
2022-07-11 16:37:59.481 INFO 96854 --- [ main] b.v.s.SpringBootWebNativeApplication : No active profile set, falling back to 1 default profile: "default"
2022-07-11 16:37:59.522 INFO 96854 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-07-11 16:37:59.523 INFO 96854 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-07-11 16:37:59.523 INFO 96854 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.64]
2022-07-11 16:37:59.529 INFO 96854 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-07-11 16:37:59.529 INFO 96854 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 47 ms
2022-07-11 16:37:59.548 INFO 96854 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-07-11 16:37:59.550 INFO 96854 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.9.Final
2022-07-11 16:37:59.552 INFO 96854 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-07-11 16:37:59.555 INFO 96854 --- [ main] com.zaxxer.hikari.HikariDataSource : hikari-pool - Starting...
2022-07-11 16:37:59.580 INFO 96854 --- [ main] com.zaxxer.hikari.HikariDataSource : hikari-pool - Start completed.
2022-07-11 16:37:59.580 INFO 96854 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL95Dialect
2022-07-11 16:37:59.583 ERROR 96854 --- [ main] 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
2022-07-11 16:37:59.583 WARN 96854 --- [ main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Invocation of init method failed; nested exception is org.hibernate.AssertionFailure: Error calling ServiceLoader.Provider.type()
2022-07-11 16:37:59.583 INFO 96854 --- [ main] com.zaxxer.hikari.HikariDataSource : hikari-pool - Shutdown initiated...
2022-07-11 16:37:59.583 INFO 96854 --- [ main] com.zaxxer.hikari.HikariDataSource : hikari-pool - Shutdown completed.
2022-07-11 16:37:59.583 INFO 96854 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-07-11 16:37:59.585 ERROR 96854 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Invocation of init method failed; nested exception is org.hibernate.AssertionFailure: Error calling ServiceLoader.Provider.type()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-boot-web-native:5.3.21]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-boot-web-native:5.3.21]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-boot-web-native:5.3.21]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-boot-web-native:5.3.21]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-web-native:2.7.1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-web-native:2.7.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-web-native:2.7.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-web-native:2.7.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-web-native:2.7.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-web-native:2.7.1]
at by.vk.springbootwebnative.SpringBootWebNativeApplication.main(SpringBootWebNativeApplication.java:10) ~[spring-boot-web-native:na]
Caused by: org.hibernate.AssertionFailure: Error calling ServiceLoader.Provider.type()
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.collectServiceIfNotDuplicate(AggregatedServiceLoader.java:272) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.loadAll(AggregatedServiceLoader.java:201) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.getAll(AggregatedServiceLoader.java:187) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:251) ~[na:na]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:390) ~[na:na]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:132) ~[na:na]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) ~[na:na]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) ~[na:na]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[na:na]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-boot-web-native:5.3.21]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-boot-web-native:5.3.21]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-boot-web-native:5.3.21]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-boot-web-native:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-boot-web-native:5.3.21]
... 16 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.collectServiceIfNotDuplicate(AggregatedServiceLoader.java:269) ~[na:na]
... 30 common frames omitted

In spite of this, ./gradlew bootRun works perfectly.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 11, 2022
@mhalbritter
Copy link
Contributor

mhalbritter commented Jul 11, 2022

I don't see funky stuff in your application which could lead to a failure. But you have com.vladmihalcea:hibernate-types-55:2.16.3 in your application. Spring Native doesn't have support for that library yet. Just adding it to the classpath messes with Hibernate in a way which breaks the native image.

Hopefully we can fix this with Spring Boot 3.

@mhalbritter mhalbritter added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 11, 2022
@fragaLY
Copy link
Author

fragaLY commented Jul 15, 2022

Hm...

@vladmihalcea, could you probably suggest any solution?

@fragaLY
Copy link
Author

fragaLY commented Jul 15, 2022

I've decided not to invent the wheel and removed com.vladmihalcea:hibernate-types-55:2.16.3 from dependencies.

As a result, I have a fully working solution.

Yeah, well, I built my own theme park, with blackjack and spring native.

The example is here: https://github.com/fragaLY/performance-researches/tree/master/spring-boot-web-native

The result of performance compared with the default web implementation: https://github.com/fragaLY/performance-researches/tree/master/spring-boot-web I could provide later. For sure, if you will need it.

FYI: @mhalbritter

@vladmihalcea
Copy link

@fragaLY Hibernate Types does not provide support for native environments. It's unlikely that it will work as it hadn't worked on Quarkus with GraalVM

vladmihalcea/hypersistence-utils#202

If anyone wants to make it work for native environments, feel free to provide a Pull Request.

@fragaLY
Copy link
Author

fragaLY commented Jul 15, 2022

@vladmihalcea , I have a workaround at the moment. So, if I will have free time I could contribute.
And thank you for a quick response. And for your job. Happy Friday!

@vladmihalcea
Copy link

All the best!

@ducanh2110
Copy link

ducanh2110 commented Sep 15, 2022

@mhalbritter Hi. I have the same problems without using hibernate-types. Here is my pom https://gist.github.com/ducanh2110/246f783c71a3660aa60b5af4be068d80
Please help me know where is the problem. Thanks so much

@sdeleuze sdeleuze closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2022
@sdeleuze
Copy link
Contributor

@ducanh2110 If you want some help, please create a dedicated issue with a full repro. Since we are focusing on Spring Boot 3 native support, I advise you to test with Spring Boot 3 M5 which has just been released, since on Spring Native side we will only fix critical issues.

@ducanh2110
Copy link

@sdeleuze thanks for support. I will try spring boot 3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Development

No branches or pull requests

6 participants