diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/persist/CascadePersistJpaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/persist/CascadePersistJpaTest.java index af7aa616bbc6..ee7ed9528811 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/persist/CascadePersistJpaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/persist/CascadePersistJpaTest.java @@ -11,8 +11,10 @@ import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; +import org.hibernate.cfg.JpaComplianceSettings; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.Test; import java.util.HashSet; @@ -22,8 +24,11 @@ @Jpa(annotatedClasses = {CascadePersistJpaTest.Parent.class, - CascadePersistJpaTest.Child.class}, - jpaComplianceEnabled = true) + CascadePersistJpaTest.Child.class}, + integrationSettings = { + @Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true") + } +) public class CascadePersistJpaTest { @Test void test(EntityManagerFactoryScope scope) { Parent p = new Parent(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/JpaProxyComplianceEnabledTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/JpaProxyComplianceEnabledTest.java index fb7fb9050e88..380592479113 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/JpaProxyComplianceEnabledTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/JpaProxyComplianceEnabledTest.java @@ -10,9 +10,11 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import org.hibernate.cfg.JpaComplianceSettings; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -25,7 +27,9 @@ JpaProxyComplianceEnabledTest.Provider.class, JpaProxyComplianceEnabledTest.TelephoneNumber.class, }, - proxyComplianceEnabled = true + integrationSettings = { + @Setting(name = JpaComplianceSettings.JPA_PROXY_COMPLIANCE, value = "true") + } ) @JiraKey("HHH-19476") public class JpaProxyComplianceEnabledTest { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/CriteriaDeleteTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/CriteriaDeleteTest.java index 778803f6c876..0392bc267f00 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/CriteriaDeleteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/CriteriaDeleteTest.java @@ -4,8 +4,10 @@ */ package org.hibernate.orm.test.jpa.compliance; +import org.hibernate.cfg.JpaComplianceSettings; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -21,7 +23,7 @@ @Jpa( annotatedClasses = CriteriaDeleteTest.Person.class, - jpaComplianceEnabled = true + integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true")} ) public class CriteriaDeleteTest { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/NegatedPredicateTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/NegatedPredicateTest.java index ba5920dc0c34..5c67bcb1b0f6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/NegatedPredicateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/NegatedPredicateTest.java @@ -6,9 +6,11 @@ import java.util.List; +import org.hibernate.cfg.JpaComplianceSettings; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,8 +51,7 @@ public void tearDown(EntityManagerFactoryScope scope) { } @Jpa( - annotatedClasses = {Wall.class}, - jpaComplianceEnabled = false + annotatedClasses = {Wall.class} ) @Test public void testNegatedPredicate(EntityManagerFactoryScope scope) { @@ -75,8 +76,7 @@ public void testNegatedPredicate(EntityManagerFactoryScope scope) { } @Jpa( - annotatedClasses = {Wall.class}, - jpaComplianceEnabled = false + annotatedClasses = {Wall.class} ) @Test public void testDoubleNegatedPredicate(EntityManagerFactoryScope scope) { @@ -106,7 +106,7 @@ public void testDoubleNegatedPredicate(EntityManagerFactoryScope scope) { @Jpa( annotatedClasses = {Wall.class}, - jpaComplianceEnabled = true + integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true")} ) @Test public void testJpaCompliantNegatedPredicate(EntityManagerFactoryScope scope) { @@ -132,7 +132,7 @@ public void testJpaCompliantNegatedPredicate(EntityManagerFactoryScope scope) { @Jpa( annotatedClasses = {Wall.class}, - jpaComplianceEnabled = true + integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true")} ) @Test public void testJpaCompliantDoubleNegatedPredicate(EntityManagerFactoryScope scope) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/emops/GetReferenceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/emops/GetReferenceTest.java index 4e40845df5b6..f652f4f461f0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/emops/GetReferenceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/emops/GetReferenceTest.java @@ -4,8 +4,10 @@ */ package org.hibernate.orm.test.jpa.emops; +import org.hibernate.cfg.JpaComplianceSettings; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.fail; @@ -20,7 +22,7 @@ Race.class, Mail.class }, - loadByIdComplianceEnabled = true + integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_LOAD_BY_ID_COMPLIANCE, value = "true")} ) public class GetReferenceTest { @Test diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/EntityManagerFactoryExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/EntityManagerFactoryExtension.java index 16c28c6ad797..711e22de2495 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/EntityManagerFactoryExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/EntityManagerFactoryExtension.java @@ -91,8 +91,8 @@ public static EntityManagerFactoryScope findEntityManagerFactoryScope( private static void collectProperties(PersistenceUnitInfoImpl pui, Jpa jpa) { final Properties properties = pui.getProperties(); properties.putAll( Environment.getProperties() ); - // JpaCompliance - setJpaComplianceProperties( properties, jpa ); + // JpaCompliance, default to false, can be overridden in the integrationSettings + properties.put( AvailableSettings.JPA_COMPLIANCE, "false" ); for ( Setting property : jpa.properties() ) { properties.setProperty( property.name(), property.value() ); } @@ -189,18 +189,6 @@ private static void setupStatementInspector(Jpa jpa, Map integra } } - private static void setJpaComplianceProperties(Properties properties, Jpa jpa) { - properties.put( AvailableSettings.JPA_COMPLIANCE, jpa.jpaComplianceEnabled() ); - properties.put( AvailableSettings.JPA_QUERY_COMPLIANCE, jpa.queryComplianceEnabled() ); - properties.put( AvailableSettings.JPA_TRANSACTION_COMPLIANCE, jpa.transactionComplianceEnabled() ); - properties.put( AvailableSettings.JPA_CLOSED_COMPLIANCE, jpa.closedComplianceEnabled() ); - properties.put( AvailableSettings.JPA_PROXY_COMPLIANCE, jpa.proxyComplianceEnabled() ); - properties.put( AvailableSettings.JPA_CACHING_COMPLIANCE, jpa.cacheComplianceEnabled() ); - properties.put( AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE, jpa.generatorScopeComplianceEnabled() ); - properties.put( AvailableSettings.JPA_ORDER_BY_MAPPING_COMPLIANCE, jpa.orderByMappingComplianceEnabled() ); - properties.put( AvailableSettings.JPA_LOAD_BY_ID_COMPLIANCE, jpa.loadByIdComplianceEnabled() ); - } - private static DomainModelDescriptor instantiateDomainModelDescriptor( Class modelDescriptorClass) { // first, see if it has a static singleton reference and use that if so diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/Jpa.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/Jpa.java index c8681ce2864c..26f236357bf9 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/Jpa.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/Jpa.java @@ -14,8 +14,6 @@ import jakarta.persistence.ValidationMode; import jakarta.persistence.spi.PersistenceUnitTransactionType; -import org.hibernate.jpa.spi.JpaCompliance; - import org.hibernate.testing.jdbc.SQLStatementInspector; import org.hibernate.testing.orm.domain.DomainModelDescriptor; import org.hibernate.testing.orm.domain.StandardDomainModel; @@ -61,51 +59,6 @@ SharedCacheMode sharedCacheMode() default SharedCacheMode.UNSPECIFIED; ValidationMode validationMode() default ValidationMode.NONE; - /** - * @see org.hibernate.cfg.AvailableSettings#JPA_COMPLIANCE - */ - boolean jpaComplianceEnabled() default false; - - /** - * @see JpaCompliance#isJpaQueryComplianceEnabled() - */ - boolean queryComplianceEnabled() default false; - - /** - * @see JpaCompliance#isJpaTransactionComplianceEnabled() - */ - boolean transactionComplianceEnabled() default false; - - /** - * @see JpaCompliance#isJpaClosedComplianceEnabled() - */ - boolean closedComplianceEnabled() default false; - - /** - * @see JpaCompliance#isJpaOrderByMappingComplianceEnabled() - */ - boolean orderByMappingComplianceEnabled() default false; - - /** - * @see JpaCompliance#isJpaProxyComplianceEnabled() - */ - boolean proxyComplianceEnabled() default false; - - /** - * @see JpaCompliance#isJpaCacheComplianceEnabled() - */ - boolean cacheComplianceEnabled() default false; - - /** - * @see JpaCompliance#isGlobalGeneratorScopeEnabled() - */ - boolean generatorScopeComplianceEnabled() default false; - - /** - * @see JpaCompliance#isLoadByIdComplianceEnabled() - */ - boolean loadByIdComplianceEnabled() default false; - boolean excludeUnlistedClasses() default false; StandardDomainModel[] standardModels() default {}; diff --git a/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/EntityManagerFactoryScopeTesting.java b/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/EntityManagerFactoryScopeTesting.java index c65007d66989..91aa6fea4740 100644 --- a/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/EntityManagerFactoryScopeTesting.java +++ b/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/EntityManagerFactoryScopeTesting.java @@ -6,6 +6,7 @@ import java.util.Set; +import org.hibernate.cfg.JpaComplianceSettings; import org.hibernate.dialect.H2Dialect; import org.hibernate.testing.annotations.AnEntity; @@ -13,6 +14,7 @@ import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -46,9 +48,7 @@ public void setup(EntityManagerFactoryScope scope) { @AfterAll public void tearDown(EntityManagerFactoryScope scope) { scope.inTransaction( - entityManager -> { - entityManager.createQuery( "delete from AnEntity" ).executeUpdate(); - } + entityManager -> entityManager.createQuery( "delete from AnEntity" ).executeUpdate() ); } @@ -67,7 +67,6 @@ public void nonAnnotatedMethodTest(EntityManagerFactoryScope scope) { Set> entities = scope.getEntityManagerFactory().getMetamodel().getEntities(); assertEquals( 1, entities.size() ); assertEquals( "AnEntity", entities.iterator().next().getName() ); - assertEquals( Boolean.FALSE, scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) ); scope.inEntityManager( entityManager -> { AnEntity ae = entityManager.find( AnEntity.class, 1 ); @@ -80,7 +79,7 @@ public void nonAnnotatedMethodTest(EntityManagerFactoryScope scope) { @Jpa( annotatedClasses = AnotherEntity.class, - queryComplianceEnabled = true + integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_QUERY_COMPLIANCE, value = "true")} ) @Test public void annotatedMethodTest(EntityManagerFactoryScope scope) { @@ -89,7 +88,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) { Set> entities = scope.getEntityManagerFactory().getMetamodel().getEntities(); assertEquals( 1, entities.size() ); assertEquals( "AnotherEntity", entities.iterator().next().getName() ); - assertEquals( Boolean.TRUE, scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) ); + assertEquals( "true", scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) ); scope.inTransaction( entityManager -> { AnotherEntity aoe = new AnotherEntity( 2, "AnotherEntity_1" ); @@ -107,9 +106,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) { Assertions.assertThrows( IllegalArgumentException.class, () -> scope.inTransaction( - entityManager -> { - AnEntity ae = entityManager.find( AnEntity.class, 1 ); - } + entityManager -> entityManager.find( AnEntity.class, 1 ) ) ); } diff --git a/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/MoreEntityManagerFactoryScopeTesting.java b/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/MoreEntityManagerFactoryScopeTesting.java index d52593cd5a00..249256b5ca03 100644 --- a/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/MoreEntityManagerFactoryScopeTesting.java +++ b/hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/MoreEntityManagerFactoryScopeTesting.java @@ -6,6 +6,7 @@ import java.util.Set; +import org.hibernate.cfg.JpaComplianceSettings; import org.hibernate.dialect.H2Dialect; import org.hibernate.testing.annotations.AnEntity; @@ -13,6 +14,7 @@ import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -43,7 +45,7 @@ public void testBasicUsage(EntityManagerFactoryScope scope) { @Jpa( annotatedClasses = AnotherEntity.class, - queryComplianceEnabled = true + integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_QUERY_COMPLIANCE, value = "true")} ) @Test public void annotatedMethodTest(EntityManagerFactoryScope scope) { @@ -52,7 +54,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) { Set> entities = scope.getEntityManagerFactory().getMetamodel().getEntities(); assertEquals( 1, entities.size() ); assertEquals( "AnotherEntity", entities.iterator().next().getName() ); - assertEquals( Boolean.TRUE, scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) ); + assertEquals( "true", scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) ); scope.inTransaction( entityManager -> { AnotherEntity aoe = new AnotherEntity( 2, "AnotherEntity_1" ); @@ -70,9 +72,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) { Assertions.assertThrows( IllegalArgumentException.class, () -> scope.inTransaction( - entityManager -> { - AnEntity ae = entityManager.find( AnEntity.class, 1 ); - } + entityManager -> entityManager.find( AnEntity.class, 1 ) ) ); } diff --git a/migration-guide.adoc b/migration-guide.adoc index 8efeb1a8da03..fed839d528f2 100644 --- a/migration-guide.adoc +++ b/migration-guide.adoc @@ -40,6 +40,39 @@ See the link:{releaseSeriesBase}#whats-new[website] for the list of new features This section describes changes to contracts (classes, interfaces, methods, etc.) which are considered https://hibernate.org/community/compatibility-policy/#api[API]. +[[jpa]] +=== @Jpa (hibernate-testing) + +The following methods have been removed from the `@Jpa` test utility, located in the hibernate-testing project: + +- `jpaComplianceEnabled()` +- `queryComplianceEnabled()` +- `transactionComplianceEnabled()` +- `closedComplianceEnabled()` +- `orderByMappingComplianceEnabled()` +- `proxyComplianceEnabled()` +- `cacheComplianceEnabled()` +- `generatorScopeComplianceEnabled()` +- `loadByIdComplianceEnabled()` + +The default value for these settings is still `false`. + +To indicate a specific flag setting, or to override the generic value that was set with `JpaComplianceSettings.JPA_COMPLIANCE`, `@Jpa` 's `integrationSettings` array should be used. + +Example: + +``` +@Jpa(annotatedClasses = + ..., + integrationSettings = { + // set all jpa compliance flags to true + @Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true"), + // override or set a specific flag value to false + @Setting(name = JpaComplianceSettings.JPA_PROXY_COMPLIANCE, value = "false") + } +) +``` + [[lock-options]] === LockOptions