Skip to content

Commit

Permalink
Log on startup that persistence.xml will lead to Quarkus-configured P…
Browse files Browse the repository at this point in the history
…Us being ignored
  • Loading branch information
yrodiere committed Jan 17, 2023
1 parent 85c79a0 commit 71c9ec5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 71c9ec5

Please sign in to comment.