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 4c59cb6647c1b5..51a4d6e6f0307a 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 @@ -880,6 +880,17 @@ private void handleHibernateORMWithNoPersistenceXml( + "To use persistence.xml files, remove all '" + HIBERNATE_ORM_CONFIG_PREFIX + "*' properties from the Quarkus config file."); } else { + // It's theoretically possible to use the Quarkus Hibernate ORM extension + // without setting any build-time configuration property, + // so the condition above might not catch all attempts to use persistence.xml and Quarkus-configured PUs + // at the same time. + // At that point, the only thing we can do is log something, + // so that hopefully people in that situation will notice that their Quarkus configuration is being ignored. + LOG.infof( + "A legacy persistence.xml file is present in the classpath. This file will be used to configure JPA/Hibernate ORM persistence units," + + " and any configuration of the Hibernate ORM extension will be ignored." + + " To ignore persistence.xml files instead, set the configuration property" + + " 'quarkus.hibernate-orm.persistence-xml.ignore' to 'true'."); return; } } diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/persistence/PersistenceXmlTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/persistence/PersistenceXmlTest.java index 192432b4f112f9..5439e4bb98e665 100644 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/persistence/PersistenceXmlTest.java +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/persistence/PersistenceXmlTest.java @@ -1,11 +1,16 @@ package io.quarkus.hibernate.orm.xml.persistence; +import static org.assertj.core.api.Assertions.assertThat; import static org.hibernate.cfg.AvailableSettings.PERSISTENCE_UNIT_NAME; +import java.util.logging.Formatter; +import java.util.logging.Level; + import javax.inject.Inject; import javax.persistence.EntityManager; import javax.transaction.Transactional; +import org.jboss.logmanager.formatters.PatternFormatter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -19,8 +24,19 @@ */ public class PersistenceXmlTest { + private static final Formatter LOG_FORMATTER = new PatternFormatter("%s"); @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() + .setLogRecordPredicate(record -> record.getLevel().equals(Level.INFO)) + .assertLogRecords(records -> assertThat(records) + .as("Logs on startup") + .anySatisfy(record -> { + assertThat(LOG_FORMATTER.formatMessage(record)) + .contains("A legacy persistence.xml file is present in the classpath", + "any configuration of the Hibernate ORM extension will be ignored", + "To ignore persistence.xml files", + "set the configuration property 'quarkus.hibernate-orm.persistence-xml.ignore' to 'true'"); + })) .withApplicationRoot((jar) -> jar .addClass(SmokeTestUtils.class) .addClass(MyEntity.class)