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

Hibernate spatial failing when running in native #233

Closed
neogeogre opened this issue Feb 15, 2023 · 3 comments · Fixed by #502
Closed

Hibernate spatial failing when running in native #233

neogeogre opened this issue Feb 15, 2023 · 3 comments · Fixed by #502
Labels
bug Something isn't working

Comments

@neogeogre
Copy link

Describe the bug

Hibernate spatial is failing when running in native image.

To Reproduce

Create a spring boot 3.0.2 project using hibernate-spatial in build.gradle.kts:

implementation("org.hibernate.orm:hibernate-spatial:6.1.7.Final")

application.yaml:

spring:
  jpa:
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    database: postgresql

The native image generation is working with ./gradlew clean nativeCompile, but then running the executable will generate the error log bellow.

Expected behavior

Expected behavior is to have the spring boot app starting properly, like it is already the case when using the JVM with ./gradlew bootRun, the error does not appear.

Logs

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.2)

2023-02-15T15:43:23.174+01:00  INFO 31733 --- [           main] io.myApp.AppKt                : Starting AOT-processed AppKt using Java 17.0.5 with PID 31733 (/home/geoffrey/Desktop/gitlab/geozone-service2/build/native/nativeCompile/geozone-service2 started by geoffrey in /home/geoffrey/Desktop/gitlab/geozone-service2)
2023-02-15T15:43:23.174+01:00  INFO 31733 --- [           main] io.myApp.AppKt                : No active profile set, falling back to 1 default profile: "default"
2023-02-15T15:43:23.204+01:00  INFO 31733 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-02-15T15:43:23.204+01:00  INFO 31733 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-02-15T15:43:23.204+01:00  INFO 31733 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.5]
2023-02-15T15:43:23.208+01:00  INFO 31733 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-02-15T15:43:23.208+01:00  INFO 31733 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 34 ms
2023-02-15T15:43:23.231+01:00  INFO 31733 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-02-15T15:43:23.232+01:00  INFO 31733 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.1.6.Final
2023-02-15T15:43:23.232+01:00  WARN 31733 --- [           main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': null
2023-02-15T15:43:23.232+01:00  INFO 31733 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-02-15T15:43:23.233+01:00 ERROR 31733 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': null
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1751) ~[geozone-service2:6.0.4]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) ~[geozone-service2:6.0.4]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[geozone-service2:6.0.4]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[geozone-service2:6.0.4]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[geozone-service2:6.0.4]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[geozone-service2:6.0.4]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[geozone-service2:6.0.4]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1130) ~[geozone-service2:6.0.4]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:905) ~[geozone-service2:6.0.4]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) ~[geozone-service2:6.0.4]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[geozone-service2:3.0.2]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[geozone-service2:3.0.2]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[geozone-service2:3.0.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[geozone-service2:3.0.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[geozone-service2:3.0.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[geozone-service2:3.0.2]
	at io.myApp.AppKt.main(App.kt:19) ~[geozone-service2:na]
Caused by: java.lang.ExceptionInInitializerError: null
	at org.hibernate.spatial.integration.SpatialInitializer.contribute(SpatialInitializer.java:22) ~[geozone-service2:6.1.7.Final]
	at org.hibernate.boot.registry.StandardServiceRegistryBuilder.applyServiceContributors(StandardServiceRegistryBuilder.java:383) ~[geozone-service2:6.1.6.Final]
	at org.hibernate.boot.registry.StandardServiceRegistryBuilder.build(StandardServiceRegistryBuilder.java:362) ~[geozone-service2:6.1.6.Final]
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:265) ~[geozone-service2:6.1.6.Final]
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:189) ~[geozone-service2:6.1.6.Final]
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[na:na]
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376) ~[geozone-service2:na]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[geozone-service2:na]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[geozone-service2:na]
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352) ~[geozone-service2:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1797) ~[geozone-service2:6.0.4]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1747) ~[geozone-service2:6.0.4]
	... 16 common frames omitted
Caused by: java.lang.IllegalArgumentException: Invalid logger interface org.hibernate.spatial.HSMessageLogger (implementation not found in jdk.internal.loader.ClassLoaders$AppClassLoader@f5f2bb7)
	at org.jboss.logging.Logger.doGetMessageLogger(Logger.java:2564) ~[geozone-service2:3.5.0.Final]
	at org.jboss.logging.Logger.getMessageLogger(Logger.java:2530) ~[geozone-service2:3.5.0.Final]
	at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516) ~[geozone-service2:3.5.0.Final]
	at org.hibernate.spatial.integration.SpatialService.<clinit>(SpatialService.java:29) ~[na:na]
	... 28 common frames omitted

System Info (please complete the following information):

  • OS: ubuntu 22.04
  • GraalVM Version 22.3.0
  • Java Version Java 17 CE
  • Plugin version 0.9.18
@neogeogre neogeogre added the bug Something isn't working label Feb 15, 2023
@sdeleuze
Copy link
Collaborator

sdeleuze commented May 24, 2023

@neogeogre Looks like missing logger reflection entries, similar to what I did in #298 for Hibernate ORM 6.2. Could you maybe try to craft a PR to add missing reflection entries for *_$logger (including the org.hibernate.spatial.HSMessageLogger one from the error message) in Hibernate Spatial like I did in my PR (with tests if possible depending on class/method visibility)?

@RMCampos
Copy link

Hey team! Is there any updates on this? I'm having the same issue. Can we temporarily fix this with the RuntimeHintsRegistrar?

sdeleuze added a commit to sdeleuze/graalvm-reachability-metadata that referenced this issue Jun 6, 2024
@sdeleuze
Copy link
Collaborator

sdeleuze commented Jun 6, 2024

Should be fixed by #502.

As a workaround, you can use with Spring:

@SpringBootApplication
@ImportRuntimeHints(DemoApplication.Hints.class)
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	static class Hints implements RuntimeHintsRegistrar {

		@Override
		public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
			hints.reflection().registerType(TypeReference.of("org.hibernate.spatial.HSMessageLogger_$logger"),
					typeHint -> typeHint.withConstructor(List.of(TypeReference.of("org.jboss.logging.Logger")), ExecutableMode.INVOKE));
		}
	}

}

sdeleuze added a commit to sdeleuze/graalvm-reachability-metadata that referenced this issue Jun 6, 2024
sdeleuze added a commit that referenced this issue Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants