quarkus: Hibernate post-boot schema-validation fails with Google Spanner after upgrade to Quarkus 2.7.5
Describe the bug
When migrating from Quarkus version 1.13.6 to 2.7., I´m facing the following error:
2022-04-04 15:06:59,391 ERROR [io.qua.hib.orm.run.sch.SchemaManagementIntegrator] (Hibernate post-boot validation thread for <default>) Failed to validate Schema: Schema-validation: missing table [RentedCars]
2022-04-04 15:06:59,703 ERROR [io.qua.hib.orm.run.sch.SchemaManagementIntegrator] (Hibernate post-boot validation thread for <default>) The following SQL may resolve the database issues, as generated by the Hibernate schema migration tool. WARNING: You must manually verify this SQL is correct, this is a best effort guess, do not copy/paste it without verifying that it does what you expect.
After googling, I saw there was an error with the same error at https://github.com/quarkusio/quarkus/issues/23445. But the version I´m trying to use already contains the fix. Then I started to analyse and debug it, and then I´ve found that seems there is another bug.
so let me give you some context information.
- quarkus: 2.7.5-final
- google-cloud-spanner-hibernate-dialect 1,5,2
- google-cloud-spanner-jdbc: 2.5.6
- Quarkus microservice with two databases: First and default with read and write access, second with only read access.
- Database 1 (default) has table RentedCars and database 2 (read-database) Cars
- application configuration
datasource:
db-kind: other
jdbc:
url: jdbc:cloudspanner://localhost:9011/projects/test-integration/instances/test-integration/databases/test-integration;usePlainText=true
driver: com.google.cloud.spanner.jdbc.JdbcDriver
"read-database":
db-kind: other
jdbc:
url: jdbc:cloudspanner://localhost:9010/projects/test-integration/instances/test-integration/databases/test-integration;usePlainText=true
driver: com.google.cloud.spanner.jdbc.JdbcDriver
hibernate-orm:
datasource: <default>
dialect: com.google.cloud.spanner.hibernate.SpannerDialect
packages: com.renting.rent
"read-database":
datasource: read-database
dialect: com.google.cloud.spanner.hibernate.SpannerDialect
packages: com.renting.cars
Testing it, I´ve seen that adding in the application configuration for the default
database:
generation: update
The table RentedCars is created in the second database. It explains why the table is not found in default because it checking in the wrong database.
Debugging quarkus code, I´ve found that in SchemaManagementIntegrator.runPostBootValidation(…) when getting the validator for “<default>” the validator.tool.serviceRegistry.configurationsValues contains hibernate.ejb.persistenceUnitName -> read-database instead of “<default>”
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
configure in application-yml two databases which already define the tables, having database generation to none for both.
- Define databases as follow database 1
CREATE TABLE IF NOT EXISTS RentedCars (
CarId VARCHAR(64),
Start DATETIME,
End DATETIME
);
database 2
CREATE TABLE IF NOT EXISTS Cars (
Id VARCHAR(64),
Description VARCHAR(255)
);
- Create a micro service with 2 entities (one for each table)
- Configure the datasources as shown in the bug description field to have each table in different databases
- Start the micro service
Automatically the error in shown
I hope this helps to solve the issue.
Thanks in advance
Output of uname -a
or ver
No response
Output of java -version
openjdk 11.0.9 2020-10-20 LTS
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.7.5-final
Build tool (ie. output of mvnw --version
or gradlew --version
)
apache-maven-3.8.2
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (10 by maintainers)
You can set
quarkus.hibernate-orm.validate-in-dev-mode
/quarkus.hibernate-orm.my-persistence-unit.validate-in-dev-mode
tofalse
.However, the problem goes beyond validation: anything related to schema initialization through Hibernate ORM with Spanner is likely to produce incorrect results as well. For example, schema management will not work correctly. The Dev UI that displays SQL to create/drop the schema will display incorrect SQL. The button in the Dev UI that recreates the database will not work correctly.
Really, the problem is in
google-cloud-spanner-hibernate
and should be solved there. I opened an issue: https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/issues/406Yes, I know. I thought it was the issue the comment I quoted was referring to.
Hi Yoann, when writing the issue description, I gave different names to the tables and databases due to company privacy where I work 😃, and then I added a typo when writing the table name.
The microservice is working ok with version 1.13.6, having a similar application configuration I provided. The issue appears when migrating to the new quarkus version.
Let me prepare a full code example to reproduce it