diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java index cced0279109e9..ed0354c6797a0 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java @@ -17,6 +17,7 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; @@ -555,7 +556,7 @@ private void handleHibernateORMWithNoPersistenceXml( .filter(i -> i.isDefault()) .findFirst(); - Set storageEngines = new HashSet<>(); + Set storageEngineCollector = new HashSet<>(); if ((defaultJdbcDataSource.isPresent() && hibernateOrmConfig.persistenceUnits.isEmpty()) || hibernateOrmConfig.defaultPersistenceUnit.isAnyPropertySet()) { @@ -565,11 +566,8 @@ private void handleHibernateORMWithNoPersistenceXml( modelClassesPerPersistencesUnits.getOrDefault(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, Collections.emptySet()), jdbcDataSources, applicationArchivesBuildItem, launchMode, capabilities, - systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors); - - if (hibernateOrmConfig.defaultPersistenceUnit.dialect.storageEngine.isPresent()) { - storageEngines.add(hibernateOrmConfig.defaultPersistenceUnit.dialect.storageEngine.get()); - } + systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, + storageEngineCollector); } for (Entry persistenceUnitEntry : hibernateOrmConfig.persistenceUnits @@ -578,14 +576,11 @@ private void handleHibernateORMWithNoPersistenceXml( hibernateOrmConfig, persistenceUnitEntry.getKey(), persistenceUnitEntry.getValue(), modelClassesPerPersistencesUnits.getOrDefault(persistenceUnitEntry.getKey(), Collections.emptySet()), jdbcDataSources, applicationArchivesBuildItem, launchMode, capabilities, - systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors); - - if (persistenceUnitEntry.getValue().dialect.storageEngine.isPresent()) { - storageEngines.add(persistenceUnitEntry.getValue().dialect.storageEngine.get()); - } + systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, + storageEngineCollector); } - if (storageEngines.size() > 1) { + if (storageEngineCollector.size() > 1) { throw new ConfigurationException( "The dialect storage engine is a global configuration property: it must be consistent across all persistence units."); } @@ -603,7 +598,8 @@ private static void producePersistenceUnitDescriptorFromConfig( BuildProducer systemProperties, BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles, - BuildProducer persistenceUnitDescriptors) { + BuildProducer persistenceUnitDescriptors, + Set storageEngineCollector) { // Find the associated datasource JdbcDataSourceBuildItem jdbcDataSource; String dataSource; @@ -786,6 +782,11 @@ private static void producePersistenceUnitDescriptorFromConfig( descriptor.getProperties().setProperty(AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK.name()); } + // Collect the storage engines if MySQL or MariaDB + if (isMySQLOrMariaDB(dialect.get()) && persistenceUnitConfig.dialect.storageEngine.isPresent()) { + storageEngineCollector.add(persistenceUnitConfig.dialect.storageEngine.get()); + } + persistenceUnitDescriptors.produce( new PersistenceUnitDescriptorBuildItem(descriptor, dataSource, getMultiTenancyStrategy(hibernateOrmConfig), @@ -999,4 +1000,9 @@ private static Class[] toArray(final Set> interfaces) { } return interfaces.toArray(new Class[interfaces.size()]); } + + private static boolean isMySQLOrMariaDB(String dialect) { + String lowercaseDialect = dialect.toLowerCase(Locale.ROOT); + return lowercaseDialect.contains("mysql") || lowercaseDialect.contains("mariadb"); + } } diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/multiplepersistenceunits/MultiplePersistenceUnitsInconsistentStorageEnginesTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/multiplepersistenceunits/MultiplePersistenceUnitsInconsistentStorageEnginesTest.java index 7f9608cc8df04..e9b985539d6c4 100644 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/multiplepersistenceunits/MultiplePersistenceUnitsInconsistentStorageEnginesTest.java +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/multiplepersistenceunits/MultiplePersistenceUnitsInconsistentStorageEnginesTest.java @@ -1,5 +1,6 @@ package io.quarkus.hibernate.orm.multiplepersistenceunits; +import org.hibernate.dialect.H2Dialect; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.jupiter.api.Assertions; @@ -30,4 +31,10 @@ public void testInvalidConfiguration() { // deployment exception should happen first Assertions.fail(); } + + /** + * This is just to have the dialect matching MySQL and trigger the MySQL + storage engines check. + */ + public static class H2DialectWithMySQLInTheName extends H2Dialect { + } } diff --git a/extensions/hibernate-orm/deployment/src/test/resources/application-multiple-persistence-units-inconsistent-storage-engines.properties b/extensions/hibernate-orm/deployment/src/test/resources/application-multiple-persistence-units-inconsistent-storage-engines.properties index 439a990e889c3..c96d09e31c934 100644 --- a/extensions/hibernate-orm/deployment/src/test/resources/application-multiple-persistence-units-inconsistent-storage-engines.properties +++ b/extensions/hibernate-orm/deployment/src/test/resources/application-multiple-persistence-units-inconsistent-storage-engines.properties @@ -7,18 +7,18 @@ quarkus.datasource.users.jdbc.url=jdbc:h2:mem:users;DB_CLOSE_DELAY=-1 quarkus.datasource.inventory.db-kind=h2 quarkus.datasource.inventory.jdbc.url=jdbc:h2:mem:inventory;DB_CLOSE_DELAY=-1 -quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect +quarkus.hibernate-orm.dialect=io.quarkus.hibernate.orm.multiplepersistenceunits.MultiplePersistenceUnitsInconsistentStorageEnginesTest$H2DialectWithMySQLInTheName quarkus.hibernate-orm.dialect.storage-engine=engine1 quarkus.hibernate-orm.database.generation=drop-and-create quarkus.hibernate-orm.packages=io.quarkus.hibernate.orm.multiplepersistenceunits.model -quarkus.hibernate-orm."users".dialect=org.hibernate.dialect.H2Dialect +quarkus.hibernate-orm."users".dialect=io.quarkus.hibernate.orm.multiplepersistenceunits.MultiplePersistenceUnitsInconsistentStorageEnginesTest$H2DialectWithMySQLInTheName quarkus.hibernate-orm."users".dialect.storage-engine=engine2 quarkus.hibernate-orm."users".database.generation=drop-and-create quarkus.hibernate-orm."users".datasource=users quarkus.hibernate-orm."users".packages=io.quarkus.hibernate.orm.multiplepersistenceunits.model.user -quarkus.hibernate-orm."inventory".dialect=org.hibernate.dialect.H2Dialect +quarkus.hibernate-orm."inventory".dialect=io.quarkus.hibernate.orm.multiplepersistenceunits.MultiplePersistenceUnitsInconsistentStorageEnginesTest$H2DialectWithMySQLInTheName quarkus.hibernate-orm."inventory".database.generation=drop-and-create quarkus.hibernate-orm."inventory".datasource=inventory quarkus.hibernate-orm."inventory".packages=io.quarkus.hibernate.orm.multiplepersistenceunits.model.inventory