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 ORM tries to load import.sql #45778

Open
zakkak opened this issue Jan 22, 2025 · 2 comments
Open

Hibernate ORM tries to load import.sql #45778

zakkak opened this issue Jan 22, 2025 · 2 comments
Labels
area/hibernate-orm Hibernate ORM area/native-image kind/bug Something isn't working

Comments

@zakkak
Copy link
Contributor

zakkak commented Jan 22, 2025

Describe the bug

Despite

//Disable implicit loading of the default import script (import.sql)
descriptor.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, "");

Hibernate seems to still try to load import.sql at runtime in native-mode.

Relates to #41995

Expected behavior

import.sql should either not be loaded or be registered as a native resource.

Actual behavior

import.sql is being accessed at runtime without being registered.

com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path

   /import.sql

without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
  java.base@25/java.lang.ClassLoader.getResource(ClassLoader.java:1344)
  io.quarkus.hibernate.orm.runtime.service.FlatClassLoaderService.locateResource(FlatClassLoaderService.java:44)
  org.hibernate.tool.schema.internal.SchemaCreatorImpl.interpretLegacyImportScriptSetting(SchemaCreatorImpl.java:693)
  org.hibernate.tool.schema.internal.SchemaCreatorImpl.applyImportFiles(SchemaCreatorImpl.java:680)
  org.hibernate.tool.schema.internal.SchemaCreatorImpl.applyImportSources(SchemaCreatorImpl.java:595)
  org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:184)
  org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:142)
  org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:118)
  org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:250)
  org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.lambda$process$5(SchemaManagementToolCoordinator.java:144)
  java.base@25/java.util.HashMap.forEach(HashMap.java:1430)
  org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:141)
  io.quarkus.hibernate.orm.runtime.observers.SessionFactoryObserverForSchemaExport.sessionFactoryCreated(SessionFactoryObserverForSchemaExport.java:21)
  org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
  org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:324)
  io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:87)
  io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:72)
  jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
  jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
  io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:154)
  io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:61)
  java.base@25/java.lang.Thread.runWith(Thread.java:1460)
  java.base@25/java.lang.Thread.run(Thread.java:1447)
  org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:832)
  org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:808)

How to Reproduce?

./mvnw clean package -Dnative -Dnative.surefire.skip \
  -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-23 \
  -pl integration-tests/main/ \
  -Dquarkus.native.additional-build-args=-H:ThrowMissingRegistrationErrors=

./integration-tests/main/target/quarkus-integration-test-main-999-SNAPSHOT-runner \
  -XX:MissingRegistrationReportingMode=Warn

Output of uname -a or ver

No response

Output of java -version

No response

Mandrel or GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

cc @yrodiere

@zakkak zakkak added area/hibernate-orm Hibernate ORM area/native-image kind/bug Something isn't working labels Jan 22, 2025
Copy link

quarkus-bot bot commented Jan 22, 2025

/cc @Karm (native-image), @galderz (native-image), @gsmet (hibernate-orm)

@yrodiere
Copy link
Member

As far as I can tell this code is supposed to skip empty resources, so what we're doing in Quarkus should work:

https://github.com/hibernate/hibernate-orm/blob/879326235fe9820cc25fafbc197eb2d0ca3e076e/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java#L668-L675

... but evidently it does not.

I imagine the thing we're setting is (somehow) not propagated to options.getConfigurationValues() in SchemaCreatorImpl. We'd need to investigate why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/native-image kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants