-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17600 from leonardowestphal/hibernate-discriminat…
…or-ignore-explicit-for-joined Add 'hibernate.discriminator.ignore_explicit_for_joined' property
- Loading branch information
Showing
16 changed files
with
462 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
...kus/hibernate/orm/ignore_explicit_for_joined/IgnoreExplicitForJoinedDefaultValueTest.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,37 @@ | ||
package io.quarkus.hibernate.orm.ignore_explicit_for_joined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
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.hibernate.orm.MyEntity; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoreExplicitForJoinedDefaultValueTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MyEntity.class) | ||
.addAsResource("application-discriminator-ignore-explicit-for-joined-default-value.properties", | ||
"application.properties")); | ||
|
||
@Inject | ||
EntityManager em; | ||
|
||
@ActivateRequestContext | ||
@Test | ||
public void testDefaultValue() { | ||
Map<String, Object> properties = em.getEntityManagerFactory().getProperties(); | ||
assertEquals("false", properties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...rm/ignore_explicit_for_joined/IgnoreExplicitForJoinedDefaultValueWithMultiplePUsTest.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,47 @@ | ||
package io.quarkus.hibernate.orm.ignore_explicit_for_joined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
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.hibernate.orm.PersistenceUnit; | ||
import io.quarkus.hibernate.orm.multiplepersistenceunits.model.config.inventory.Plane; | ||
import io.quarkus.hibernate.orm.multiplepersistenceunits.model.config.user.User; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoreExplicitForJoinedDefaultValueWithMultiplePUsTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(User.class) | ||
.addClass(Plane.class) | ||
.addAsResource("application-multiple-pu-discriminator-ignore-explicit-for-joined-default-value.properties", | ||
"application.properties")); | ||
@PersistenceUnit("users") | ||
@Inject | ||
EntityManager emUsers; | ||
|
||
@PersistenceUnit("inventory") | ||
@Inject | ||
EntityManager emInventory; | ||
|
||
@ActivateRequestContext | ||
@Test | ||
public void testDefaultValue() { | ||
Map<String, Object> usersProperties = emUsers.getEntityManagerFactory().getProperties(); | ||
assertEquals("false", usersProperties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
|
||
Map<String, Object> inventoryProperties = emUsers.getEntityManagerFactory().getProperties(); | ||
assertEquals("false", inventoryProperties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ignore_explicit_for_joined/IgnoreExplicitForJoinedDefaultValueWithPersistenceXmlTest.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,42 @@ | ||
package io.quarkus.hibernate.orm.ignore_explicit_for_joined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
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.hibernate.orm.xml.persistence.MyEntity; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoreExplicitForJoinedDefaultValueWithPersistenceXmlTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(MyEntity.class) | ||
.addAsManifestResource("META-INF/persistence-discriminator-ignore-explicit-for-joined-default-value.xml", | ||
"persistence.xml") | ||
.addAsResource("application-datasource-only.properties", "application.properties")); | ||
|
||
@Inject | ||
EntityManager em; | ||
|
||
@ActivateRequestContext | ||
@Test | ||
public void testDefaultNullValue() { | ||
Map<String, Object> properties = em.getEntityManagerFactory().getProperties(); | ||
|
||
// the PU is templatePU from the persistence.xml, not the default entity manager from application.properties | ||
assertEquals("templatePU", properties.get("hibernate.ejb.persistenceUnitName")); | ||
//If not defined in persistence.xml, internally hibernate-orm will assume false as default value | ||
assertEquals(null, properties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...m/ignore_explicit_for_joined/IgnoreExplicitForJoinedFalseValueWithPersistenceXmlTest.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,41 @@ | ||
package io.quarkus.hibernate.orm.ignore_explicit_for_joined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
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.hibernate.orm.xml.persistence.MyEntity; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoreExplicitForJoinedFalseValueWithPersistenceXmlTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(MyEntity.class) | ||
.addAsManifestResource("META-INF/persistence-discriminator-ignore-explicit-for-joined-false-value.xml", | ||
"persistence.xml") | ||
.addAsResource("application-datasource-only.properties", "application.properties")); | ||
|
||
@Inject | ||
EntityManager em; | ||
|
||
@ActivateRequestContext | ||
@Test | ||
public void testFalseValue() { | ||
Map<String, Object> properties = em.getEntityManagerFactory().getProperties(); | ||
|
||
// the PU is templatePU from the persistence.xml, not the default entity manager from application.properties | ||
assertEquals("templatePU", properties.get("hibernate.ejb.persistenceUnitName")); | ||
assertEquals("false", properties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...uarkus/hibernate/orm/ignore_explicit_for_joined/IgnoreExplicitForJoinedTrueValueTest.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,37 @@ | ||
package io.quarkus.hibernate.orm.ignore_explicit_for_joined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
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.hibernate.orm.MyEntity; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoreExplicitForJoinedTrueValueTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MyEntity.class) | ||
.addAsResource("application-discriminator-ignore-explicit-for-joined-true-value.properties", | ||
"application.properties")); | ||
|
||
@Inject | ||
EntityManager em; | ||
|
||
@ActivateRequestContext | ||
@Test | ||
public void testTrueValue() { | ||
Map<String, Object> properties = em.getEntityManagerFactory().getProperties(); | ||
assertEquals("true", properties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...e/orm/ignore_explicit_for_joined/IgnoreExplicitForJoinedTrueValueWithMultiplePUsTest.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,47 @@ | ||
package io.quarkus.hibernate.orm.ignore_explicit_for_joined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
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.hibernate.orm.PersistenceUnit; | ||
import io.quarkus.hibernate.orm.multiplepersistenceunits.model.config.inventory.Plane; | ||
import io.quarkus.hibernate.orm.multiplepersistenceunits.model.config.user.User; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoreExplicitForJoinedTrueValueWithMultiplePUsTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(User.class) | ||
.addClass(Plane.class) | ||
.addAsResource("application-multiple-pu-discriminator-ignore-explicit-for-joined-true-value.properties", | ||
"application.properties")); | ||
@PersistenceUnit("users") | ||
@Inject | ||
EntityManager emUsers; | ||
|
||
@PersistenceUnit("inventory") | ||
@Inject | ||
EntityManager emInventory; | ||
|
||
@ActivateRequestContext | ||
@Test | ||
public void testTrueValue() { | ||
Map<String, Object> usersProperties = emUsers.getEntityManagerFactory().getProperties(); | ||
assertEquals("true", usersProperties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
|
||
Map<String, Object> inventoryProperties = emUsers.getEntityManagerFactory().getProperties(); | ||
assertEquals("true", inventoryProperties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...rm/ignore_explicit_for_joined/IgnoreExplicitForJoinedTrueValueWithPersistenceXmlTest.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,41 @@ | ||
package io.quarkus.hibernate.orm.ignore_explicit_for_joined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
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.hibernate.orm.xml.persistence.MyEntity; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class IgnoreExplicitForJoinedTrueValueWithPersistenceXmlTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(MyEntity.class) | ||
.addAsManifestResource("META-INF/persistence-discriminator-ignore-explicit-for-joined-true-value.xml", | ||
"persistence.xml") | ||
.addAsResource("application-datasource-only.properties", "application.properties")); | ||
|
||
@Inject | ||
EntityManager em; | ||
|
||
@ActivateRequestContext | ||
@Test | ||
public void testTrueValue() { | ||
Map<String, Object> properties = em.getEntityManagerFactory().getProperties(); | ||
|
||
// the PU is templatePU from the persistence.xml, not the default entity manager from application.properties | ||
assertEquals("templatePU", properties.get("hibernate.ejb.persistenceUnitName")); | ||
assertEquals("true", properties.get("hibernate.discriminator.ignore_explicit_for_joined")); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...resources/META-INF/persistence-discriminator-ignore-explicit-for-joined-default-value.xml
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,30 @@ | ||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence | ||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" | ||
version="2.1"> | ||
|
||
<persistence-unit name="templatePU" transaction-type="JTA"> | ||
|
||
<description>Hibernate test case template Persistence Unit</description> | ||
|
||
<class>io.quarkus.hibernate.orm.xml.persistence.MyEntity</class> | ||
|
||
<properties> | ||
<!-- intentionally using worse case so that we can optimise for this --> | ||
<property name="hibernate.archive.autodetection" value="class, hbm"/> | ||
|
||
<!-- Connection specific --> | ||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> | ||
|
||
<!-- | ||
Optimistically create the tables; | ||
will cause background errors being logged if they already exist, | ||
but is practical to retain existing data across runs (or create as needed) --> | ||
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> | ||
|
||
<property name="javax.persistence.validation.mode" value="NONE"/> | ||
</properties> | ||
|
||
</persistence-unit> | ||
</persistence> |
Oops, something went wrong.