-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually fail on startup when configuring a persistence unit in Quark…
…us config with a persistence.xml in the classpath Some code dealing with implied PUs was preventing that failure from even happening... Also note we cannot catch *every* situation where we should fail, but we can try our best.
- Loading branch information
Showing
5 changed files
with
55 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...est/java/io/quarkus/hibernate/orm/xml/persistence/PersistenceXmlAndQuarkusConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.quarkus.hibernate.orm.xml.persistence; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.runtime.configuration.ConfigurationException; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class PersistenceXmlAndQuarkusConfigTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.assertException(e -> Assertions.assertThat(e) | ||
.isInstanceOf(ConfigurationException.class) | ||
.hasMessageContainingAll( | ||
"A legacy persistence.xml file is present in the classpath, but Hibernate ORM is also configured through the Quarkus config file", | ||
"Legacy persistence.xml files and Quarkus configuration cannot be used at the same time", | ||
"To ignore persistence.xml files, set the configuration property 'quarkus.hibernate-orm.persistence-xml.ignore' to 'true'", | ||
"To use persistence.xml files, remove all 'quarkus.hibernate-orm.*' properties from the Quarkus config file.")) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(MyEntity.class) | ||
.addAsManifestResource("META-INF/some-persistence.xml", "persistence.xml")) | ||
.withConfigurationResource("application.properties") | ||
// Unfortunately the minimal config is not enough to detect that a PU is configured in Quarkus's application.properties | ||
// -- we're paying the price of our "zero config" approach. | ||
// We can only detect something is wrong if some optional properties are set. | ||
.overrideConfigKey("quarkus.hibernate-orm.fetch.max-depth", "2"); | ||
|
||
@Test | ||
public void test() { | ||
// should not be called, deployment exception should happen first: | ||
// it's illegal to have Hibernate configuration properties in both the | ||
// application.properties and in the persistence.xml | ||
Assertions.fail("Application should not start"); | ||
} | ||
|
||
} |