From 9e5c1d2f917e1e7c7616a3a512298b3df531ecab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Tue, 8 Oct 2024 10:41:04 +0200 Subject: [PATCH] Re-enable detection of the database version by default when using explicit Hibernate ORM dialects Because that detection is now done by the Hibernate ORM dialect itself, and should work properly for all dialects. --- docs/src/main/asciidoc/hibernate-orm.adoc | 6 -- ...sabledAutomaticallyPersistenceXmlTest.java | 73 ------------------- ...VersionCheckDisabledAutomaticallyTest.java | 69 ------------------ ...rsion-placeholder-and-explicit-dialect.xml | 30 -------- ...ernateOrmRuntimeConfigPersistenceUnit.java | 5 +- ...kusRuntimeInitDialectFactoryInitiator.java | 5 +- 6 files changed, 2 insertions(+), 186 deletions(-) delete mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyPersistenceXmlTest.java delete mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyTest.java delete mode 100644 extensions/hibernate-orm/deployment/src/test/resources/META-INF/some-persistence-with-h2-version-placeholder-and-explicit-dialect.xml diff --git a/docs/src/main/asciidoc/hibernate-orm.adoc b/docs/src/main/asciidoc/hibernate-orm.adoc index e8d9c7c3f5c00..cabc47812fd06 100644 --- a/docs/src/main/asciidoc/hibernate-orm.adoc +++ b/docs/src/main/asciidoc/hibernate-orm.adoc @@ -213,12 +213,6 @@ Hibernate ORM may generate SQL that is invalid which would lead to runtime excep If the database cannot be reached, a warning will be logged but startup will proceed. You can optionally disable the version check if you know the database won't be reachable on startup using <>. - -// TODO change the default to "always enabled" when we solve version detection problems -// See https://github.com/quarkusio/quarkus/issues/43703 -// See https://github.com/quarkusio/quarkus/issues/42255 -The version check is disabled by default when a dialect is set explicitly, -as a workaround for https://github.com/quarkusio/quarkus/issues/42255[#42255]/link:https://github.com/quarkusio/quarkus/issues/43703[#43703]. ==== [[hibernate-dialect-other-databases]] diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyPersistenceXmlTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyPersistenceXmlTest.java deleted file mode 100644 index 28084a93e099d..0000000000000 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyPersistenceXmlTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package io.quarkus.hibernate.orm.config.dialect; - -import static io.quarkus.hibernate.orm.ResourceUtil.loadResourceAndReplacePlaceholders; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Map; - -import jakarta.inject.Inject; -import jakarta.transaction.Transactional; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.hibernate.orm.MyEntity; -import io.quarkus.hibernate.orm.SmokeTestUtils; -import io.quarkus.hibernate.orm.runtime.config.DialectVersions; -import io.quarkus.test.QuarkusUnitTest; - -/** - * Tests that the workaround for https://github.com/quarkusio/quarkus/issues/43703 / - * https://github.com/quarkusio/quarkus/issues/42255 - * is effective. - */ -// TODO remove this test when change the default to "always enabled" when we solve version detection problems -// See https://github.com/quarkusio/quarkus/issues/43703 -// See https://github.com/quarkusio/quarkus/issues/42255 -public class DbVersionCheckDisabledAutomaticallyPersistenceXmlTest { - - private static final String ACTUAL_H2_VERSION = DialectVersions.Defaults.H2; - // We will set the DB version to something higher than the actual version: this is invalid. - private static final String CONFIGURED_DB_VERSION = "999.999.0"; - static { - assertThat(ACTUAL_H2_VERSION) - .as("Test setup - we need the required version to be different from the actual one") - .doesNotStartWith(CONFIGURED_DB_VERSION); - } - - @RegisterExtension - static QuarkusUnitTest runner = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addClass(SmokeTestUtils.class) - .addClass(MyEntity.class) - .addAsManifestResource(new StringAsset(loadResourceAndReplacePlaceholders( - "META-INF/some-persistence-with-h2-version-placeholder-and-explicit-dialect.xml", - Map.of("H2_VERSION", "999.999"))), - "persistence.xml")) - .withConfigurationResource("application-datasource-only.properties"); - - @Inject - SessionFactory sessionFactory; - - @Inject - Session session; - - @Test - public void dialectVersion() { - var dialectVersion = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - assertThat(DialectVersions.toString(dialectVersion)).isEqualTo(CONFIGURED_DB_VERSION); - } - - @Test - @Transactional - public void smokeTest() { - SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(session, - MyEntity.class, MyEntity::new, - MyEntity::getId, - MyEntity::setName, MyEntity::getName); - } -} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyTest.java deleted file mode 100644 index 9b526700c120c..0000000000000 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.quarkus.hibernate.orm.config.dialect; - -import static org.assertj.core.api.Assertions.assertThat; - -import jakarta.inject.Inject; -import jakarta.transaction.Transactional; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.hibernate.orm.MyEntity; -import io.quarkus.hibernate.orm.SmokeTestUtils; -import io.quarkus.hibernate.orm.runtime.config.DialectVersions; -import io.quarkus.test.QuarkusUnitTest; - -/** - * Tests that the workaround for https://github.com/quarkusio/quarkus/issues/43703 / - * https://github.com/quarkusio/quarkus/issues/42255 - * is effective. - */ -// TODO remove this test when change the default to "always enabled" when we solve version detection problems -// See https://github.com/quarkusio/quarkus/issues/43703 -// See https://github.com/quarkusio/quarkus/issues/42255 -public class DbVersionCheckDisabledAutomaticallyTest { - - private static final String ACTUAL_H2_VERSION = DialectVersions.Defaults.H2; - // We will set the DB version to something higher than the actual version: this is invalid. - private static final String CONFIGURED_DB_VERSION = "999.999.0"; - static { - assertThat(ACTUAL_H2_VERSION) - .as("Test setup - we need the required version to be different from the actual one") - .doesNotStartWith(CONFIGURED_DB_VERSION); - } - - @RegisterExtension - static QuarkusUnitTest runner = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addClass(SmokeTestUtils.class) - .addClass(MyEntity.class)) - .withConfigurationResource("application.properties") - .overrideConfigKey("quarkus.datasource.db-version", "999.999") - // Setting a dialect should disable the version check, so Quarkus should boot just fine - .overrideConfigKey("quarkus.hibernate-orm.dialect", H2Dialect.class.getName()); - - @Inject - SessionFactory sessionFactory; - - @Inject - Session session; - - @Test - public void dialectVersion() { - var dialectVersion = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - assertThat(DialectVersions.toString(dialectVersion)).isEqualTo(CONFIGURED_DB_VERSION); - } - - @Test - @Transactional - public void smokeTest() { - SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(session, - MyEntity.class, MyEntity::new, - MyEntity::getId, - MyEntity::setName, MyEntity::getName); - } -} diff --git a/extensions/hibernate-orm/deployment/src/test/resources/META-INF/some-persistence-with-h2-version-placeholder-and-explicit-dialect.xml b/extensions/hibernate-orm/deployment/src/test/resources/META-INF/some-persistence-with-h2-version-placeholder-and-explicit-dialect.xml deleted file mode 100644 index 2b5cd2b54d3c7..0000000000000 --- a/extensions/hibernate-orm/deployment/src/test/resources/META-INF/some-persistence-with-h2-version-placeholder-and-explicit-dialect.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - Hibernate test case template Persistence Unit - - io.quarkus.hibernate.orm.MyEntity - - - - - - - - - - - - - - - - diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java index 09cafed1b27fb..8881433f1c3e0 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java @@ -111,13 +111,10 @@ interface HibernateOrmConfigPersistenceUnitDatabase { * * @asciidoclet */ - // TODO change the default to "always enabled" when we solve version detection problems - // See https://github.com/quarkusio/quarkus/issues/43703 - // See https://github.com/quarkusio/quarkus/issues/42255 // TODO disable the check by default when offline startup is opted in // See https://github.com/quarkusio/quarkus/issues/13522 @WithName("version-check.enabled") - @ConfigDocDefault("`true` if the dialect was set automatically by Quarkus, `false` if it was set explicitly") + @ConfigDocDefault("`true`") Optional versionCheckEnabled(); } diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/service/QuarkusRuntimeInitDialectFactoryInitiator.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/service/QuarkusRuntimeInitDialectFactoryInitiator.java index 03730f2f7c1af..c5396bbb33f0d 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/service/QuarkusRuntimeInitDialectFactoryInitiator.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/service/QuarkusRuntimeInitDialectFactoryInitiator.java @@ -33,12 +33,9 @@ public QuarkusRuntimeInitDialectFactoryInitiator(String persistenceUnitName, // then the version from `DialectVersions.Defaults` will be used: this.buildTimeDbVersion = dialect.getVersion(); this.versionCheckEnabled = runtimePuConfig.database().versionCheckEnabled() - // TODO change the default to "always enabled" when we solve version detection problems - // See https://github.com/quarkusio/quarkus/issues/43703 - // See https://github.com/quarkusio/quarkus/issues/42255 // TODO disable the check by default when offline startup is opted in // See https://github.com/quarkusio/quarkus/issues/13522 - .orElse(recordedConfig.getExplicitDialect().isEmpty()); + .orElse(true); } @Override