Fix import.sql not executed when using only StatelessSession (no entities)#53419
Fix import.sql not executed when using only StatelessSession (no entities)#53419lucamolteni wants to merge 1 commit intoquarkusio:mainfrom
Conversation
…ties) When there are no @entity classes, metadata.getContributors() returns an empty set, causing SchemaManagementToolCoordinator to skip all schema actions including import.sql execution. Ensure at least one contributor exists so configured schema actions are always processed. Fixes: quarkusio#53413 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
/cc @gsmet (hibernate-orm) |
Status for workflow
|
| Status | Name | Step | Failures | Logs | Raw logs | Build scan |
|---|---|---|---|---|---|---|
| ✔️ | JVM Integration Tests - JDK 17 | Logs | Raw logs | 🔍 | ||
| ✔️ | JVM Integration Tests - JDK 17 Windows | Logs | Raw logs | 🔍 | ||
| ✔️ | JVM Integration Tests - JDK 21 | Logs | Raw logs | 🔍 | ||
| ✔️ | JVM Integration Tests - JDK 25 | Logs | Raw logs | 🔍 | ||
| ❌ | JVM Integration Tests - JDK 25 Semeru | Build |
Failures | Logs | Raw logs | 🔍 |
You can consult the Develocity build scans.
Failures
⚙️ JVM Integration Tests - JDK 25 Semeru #
- Failing: integration-tests/kubernetes-service-binding-jdbc
📦 integration-tests/kubernetes-service-binding-jdbc
❌ Failed to execute goal io.fabric8:docker-maven-plugin:0.48.1:stop (docker-start) on project quarkus-integration-test-kubernetes-service-binding-jdbc: At least one exception thrown during container removal.
Flaky tests - Develocity
⚙️ JVM Tests - JDK 17
📦 extensions/smallrye-reactive-messaging-kafka/deployment
❌ io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing.KafkaDevServicesContinuousTestingTestCase.testContinuousTestingScenario2 - History
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.io/library/redis:7-java.util.concurrent.CompletionException
Details
java.util.concurrent.CompletionException: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.io/library/redis:7
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1807)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
|
"org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.io/library/redis:7 - java.util.concurrent.CompletionException" Failure seems unrelated |
| // Even with no entities, we need at least one contributor so that | ||
| // SchemaManagementToolCoordinator processes the configured schema actions | ||
| // (e.g. executing import.sql). See https://github.com/quarkusio/quarkus/issues/53413 | ||
| return Set.of("no-entities"); |
There was a problem hiding this comment.
It looks odd to pass a dummy value. Given @mbellade gave his approval, I suppose it's the vetted way in Hibernate ORM to achieve that?
There was a problem hiding this comment.
It looks odd to pass a dummy value. Given @mbellade gave his approval, I suppose it's the vetted way in Hibernate ORM to achieve that?
good question I didn't know either, initially Claud put orm stating that was the usual case for contributors, but I checked the any string would work so I put something that would state that we're in a specific case
There was a problem hiding this comment.
@gsmet @lucamolteni I'm guessing this is necessary to circumvent the logic of this method in Hibernate ORM, which always expects at least one contributor to exist, since outside of Quarkus there will always be at least one entity mapping (and each entity mapping has its contributor).
If we wanted to avoid this "hack-ish" way of triggering ORM's built-in schema management coordinator, we would need to either modify it at the ORM-level, or introduce some custom logic when bootstrapping Hibernate in Quarkus (e.g. in FastBootEntityManagerFactoryBuilder) that manually invokes some schema manager methods for the special "no-entities" case.
There was a problem hiding this comment.
Yeah IMO this is basically working around a bug, or at least a gap, in Hibernate ORM.
@lucamolteni please file an issue in ORM and either fix it there, or at least reference the issue in a comment here?
So that's where I'm not sure I follow. Wouldn't this case of using only the |
@gsmet sure it would, we just probably never explicitly tested the functionality; AFAIK we only ever targeted this "entity-less mode" in Quarkus, but as I said:
It's a valid approach, we just need an upstream issue and someone working on it :) |
yrodiere
left a comment
There was a problem hiding this comment.
This will most likely result in breaking changes for some users who have an import.sql in their classpath by mistake -- yes it's preposterous, but we've had reports in the past.
This is also a very reasonable breaking change IMO, so we can proceed, but please write up a migration guide entry?
| // Even with no entities, we need at least one contributor so that | ||
| // SchemaManagementToolCoordinator processes the configured schema actions | ||
| // (e.g. executing import.sql). See https://github.com/quarkusio/quarkus/issues/53413 | ||
| return Set.of("no-entities"); |
There was a problem hiding this comment.
Yeah IMO this is basically working around a bug, or at least a gap, in Hibernate ORM.
@lucamolteni please file an issue in ORM and either fix it there, or at least reference the issue in a comment here?
I've created https://hibernate.atlassian.net/browse/HHH-20321 and assigned it to me |
PR for 7.3 hibernate/hibernate-orm#12138 |
Thanks. So I imagine we will close this PR (#53419) and wait for this fix to make its way into Quarkus? |
^ |
Summary
When there are no
@Entityclasses butStatelessSessionis used withimport.sql, the SQL script was not executedRoot cause:
metadata.getContributors()returns an empty set with no entities, causingSchemaManagementToolCoordinatorto skip all schema actions includingimport.sqlexecutionFix: ensure
PrevalidatedQuarkusMetadata.getContributors()always returns at least one contributor so configured schema actions are processedFixes: import.sql not executed when not defining entities #53413
Test plan
ImportSqlLoadScriptNoEntitiesTestCasethat verifiesimport.sqlruns without any@Entitysql_load_scripttests passNoEntitiestests pass🤖 Generated with Claude Code