Skip to content

Commit 78e8c58

Browse files
committed
HHH-19914 - Don't ignore the JPA_COMPLIANCE setting in @jpa
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
1 parent f50c43e commit 78e8c58

File tree

10 files changed

+70
-86
lines changed

10 files changed

+70
-86
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/persist/CascadePersistJpaTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import jakarta.persistence.Id;
1212
import jakarta.persistence.ManyToOne;
1313
import jakarta.persistence.OneToMany;
14+
import org.hibernate.cfg.JpaComplianceSettings;
1415
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1516
import org.hibernate.testing.orm.junit.Jpa;
17+
import org.hibernate.testing.orm.junit.Setting;
1618
import org.junit.jupiter.api.Test;
1719

1820
import java.util.HashSet;
@@ -22,8 +24,11 @@
2224

2325
@Jpa(annotatedClasses =
2426
{CascadePersistJpaTest.Parent.class,
25-
CascadePersistJpaTest.Child.class},
26-
jpaComplianceEnabled = true)
27+
CascadePersistJpaTest.Child.class},
28+
integrationSettings = {
29+
@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true")
30+
}
31+
)
2732
public class CascadePersistJpaTest {
2833
@Test void test(EntityManagerFactoryScope scope) {
2934
Parent p = new Parent();

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/JpaProxyComplianceEnabledTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
import jakarta.persistence.Id;
1111
import jakarta.persistence.JoinColumn;
1212
import jakarta.persistence.ManyToOne;
13+
import org.hibernate.cfg.JpaComplianceSettings;
1314
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1415
import org.hibernate.testing.orm.junit.JiraKey;
1516
import org.hibernate.testing.orm.junit.Jpa;
17+
import org.hibernate.testing.orm.junit.Setting;
1618
import org.junit.jupiter.api.BeforeAll;
1719
import org.junit.jupiter.api.Test;
1820

@@ -25,7 +27,9 @@
2527
JpaProxyComplianceEnabledTest.Provider.class,
2628
JpaProxyComplianceEnabledTest.TelephoneNumber.class,
2729
},
28-
proxyComplianceEnabled = true
30+
integrationSettings = {
31+
@Setting(name = JpaComplianceSettings.JPA_PROXY_COMPLIANCE, value = "true")
32+
}
2933
)
3034
@JiraKey("HHH-19476")
3135
public class JpaProxyComplianceEnabledTest {

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/CriteriaDeleteTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
*/
55
package org.hibernate.orm.test.jpa.compliance;
66

7+
import org.hibernate.cfg.JpaComplianceSettings;
78
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
89
import org.hibernate.testing.orm.junit.Jpa;
10+
import org.hibernate.testing.orm.junit.Setting;
911
import org.junit.jupiter.api.BeforeEach;
1012
import org.junit.jupiter.api.Test;
1113

@@ -21,7 +23,7 @@
2123

2224
@Jpa(
2325
annotatedClasses = CriteriaDeleteTest.Person.class,
24-
jpaComplianceEnabled = true
26+
integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true")}
2527
)
2628
public class CriteriaDeleteTest {
2729

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/NegatedPredicateTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import java.util.List;
88

9+
import org.hibernate.cfg.JpaComplianceSettings;
910
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1011
import org.hibernate.testing.orm.junit.JiraKey;
1112
import org.hibernate.testing.orm.junit.Jpa;
13+
import org.hibernate.testing.orm.junit.Setting;
1214
import org.junit.jupiter.api.AfterEach;
1315
import org.junit.jupiter.api.BeforeEach;
1416
import org.junit.jupiter.api.Test;
@@ -49,8 +51,7 @@ public void tearDown(EntityManagerFactoryScope scope) {
4951
}
5052

5153
@Jpa(
52-
annotatedClasses = {Wall.class},
53-
jpaComplianceEnabled = false
54+
annotatedClasses = {Wall.class}
5455
)
5556
@Test
5657
public void testNegatedPredicate(EntityManagerFactoryScope scope) {
@@ -75,8 +76,7 @@ public void testNegatedPredicate(EntityManagerFactoryScope scope) {
7576
}
7677

7778
@Jpa(
78-
annotatedClasses = {Wall.class},
79-
jpaComplianceEnabled = false
79+
annotatedClasses = {Wall.class}
8080
)
8181
@Test
8282
public void testDoubleNegatedPredicate(EntityManagerFactoryScope scope) {
@@ -106,7 +106,7 @@ public void testDoubleNegatedPredicate(EntityManagerFactoryScope scope) {
106106

107107
@Jpa(
108108
annotatedClasses = {Wall.class},
109-
jpaComplianceEnabled = true
109+
integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true")}
110110
)
111111
@Test
112112
public void testJpaCompliantNegatedPredicate(EntityManagerFactoryScope scope) {
@@ -132,7 +132,7 @@ public void testJpaCompliantNegatedPredicate(EntityManagerFactoryScope scope) {
132132

133133
@Jpa(
134134
annotatedClasses = {Wall.class},
135-
jpaComplianceEnabled = true
135+
integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true")}
136136
)
137137
@Test
138138
public void testJpaCompliantDoubleNegatedPredicate(EntityManagerFactoryScope scope) {

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/emops/GetReferenceTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
*/
55
package org.hibernate.orm.test.jpa.emops;
66

7+
import org.hibernate.cfg.JpaComplianceSettings;
78
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
89
import org.hibernate.testing.orm.junit.Jpa;
10+
import org.hibernate.testing.orm.junit.Setting;
911
import org.junit.jupiter.api.Test;
1012

1113
import static org.junit.jupiter.api.Assertions.fail;
@@ -20,7 +22,7 @@
2022
Race.class,
2123
Mail.class
2224
},
23-
loadByIdComplianceEnabled = true
25+
integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_LOAD_BY_ID_COMPLIANCE, value = "true")}
2426
)
2527
public class GetReferenceTest {
2628
@Test

hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/EntityManagerFactoryExtension.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public static Map<String, Object> getIntegrationSettings(Object testScope, Exten
9999
private static void collectProperties(PersistenceUnitInfoImpl pui, Jpa jpa) {
100100
final Properties properties = pui.getProperties();
101101
properties.putAll( Environment.getProperties() );
102-
// JpaCompliance
103-
setJpaComplianceProperties( properties, jpa );
102+
// JpaCompliance, default to false, can be overridden in the integrationSettings
103+
properties.put( AvailableSettings.JPA_COMPLIANCE, "false" );
104104
for ( Setting property : jpa.properties() ) {
105105
properties.setProperty( property.name(), property.value() );
106106
}
@@ -208,18 +208,6 @@ private static void setupStatementInspector(Jpa jpa, Map<String, Object> integra
208208
}
209209
}
210210

211-
private static void setJpaComplianceProperties(Properties properties, Jpa jpa) {
212-
properties.put( AvailableSettings.JPA_COMPLIANCE, jpa.jpaComplianceEnabled() );
213-
properties.put( AvailableSettings.JPA_QUERY_COMPLIANCE, jpa.queryComplianceEnabled() );
214-
properties.put( AvailableSettings.JPA_TRANSACTION_COMPLIANCE, jpa.transactionComplianceEnabled() );
215-
properties.put( AvailableSettings.JPA_CLOSED_COMPLIANCE, jpa.closedComplianceEnabled() );
216-
properties.put( AvailableSettings.JPA_PROXY_COMPLIANCE, jpa.proxyComplianceEnabled() );
217-
properties.put( AvailableSettings.JPA_CACHING_COMPLIANCE, jpa.cacheComplianceEnabled() );
218-
properties.put( AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE, jpa.generatorScopeComplianceEnabled() );
219-
properties.put( AvailableSettings.JPA_ORDER_BY_MAPPING_COMPLIANCE, jpa.orderByMappingComplianceEnabled() );
220-
properties.put( AvailableSettings.JPA_LOAD_BY_ID_COMPLIANCE, jpa.loadByIdComplianceEnabled() );
221-
}
222-
223211
private static DomainModelDescriptor instantiateDomainModelDescriptor(
224212
Class<? extends DomainModelDescriptor> modelDescriptorClass) {
225213
// first, see if it has a static singleton reference and use that if so

hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/Jpa.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import jakarta.persistence.ValidationMode;
1515
import jakarta.persistence.spi.PersistenceUnitTransactionType;
1616

17-
import org.hibernate.jpa.spi.JpaCompliance;
18-
1917
import org.hibernate.testing.jdbc.SQLStatementInspector;
2018
import org.hibernate.testing.orm.domain.DomainModelDescriptor;
2119
import org.hibernate.testing.orm.domain.StandardDomainModel;
@@ -63,51 +61,6 @@
6361
SharedCacheMode sharedCacheMode() default SharedCacheMode.UNSPECIFIED;
6462
ValidationMode validationMode() default ValidationMode.NONE;
6563

66-
/**
67-
* @see org.hibernate.cfg.AvailableSettings#JPA_COMPLIANCE
68-
*/
69-
boolean jpaComplianceEnabled() default false;
70-
71-
/**
72-
* @see JpaCompliance#isJpaQueryComplianceEnabled()
73-
*/
74-
boolean queryComplianceEnabled() default false;
75-
76-
/**
77-
* @see JpaCompliance#isJpaTransactionComplianceEnabled()
78-
*/
79-
boolean transactionComplianceEnabled() default false;
80-
81-
/**
82-
* @see JpaCompliance#isJpaClosedComplianceEnabled()
83-
*/
84-
boolean closedComplianceEnabled() default false;
85-
86-
/**
87-
* @see JpaCompliance#isJpaOrderByMappingComplianceEnabled()
88-
*/
89-
boolean orderByMappingComplianceEnabled() default false;
90-
91-
/**
92-
* @see JpaCompliance#isJpaProxyComplianceEnabled()
93-
*/
94-
boolean proxyComplianceEnabled() default false;
95-
96-
/**
97-
* @see JpaCompliance#isJpaCacheComplianceEnabled()
98-
*/
99-
boolean cacheComplianceEnabled() default false;
100-
101-
/**
102-
* @see JpaCompliance#isGlobalGeneratorScopeEnabled()
103-
*/
104-
boolean generatorScopeComplianceEnabled() default false;
105-
106-
/**
107-
* @see JpaCompliance#isLoadByIdComplianceEnabled()
108-
*/
109-
boolean loadByIdComplianceEnabled() default false;
110-
11164
boolean excludeUnlistedClasses() default false;
11265

11366
StandardDomainModel[] standardModels() default {};

hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/EntityManagerFactoryScopeTesting.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
import java.util.Set;
88

9+
import org.hibernate.cfg.JpaComplianceSettings;
910
import org.hibernate.dialect.H2Dialect;
1011

1112
import org.hibernate.testing.annotations.AnEntity;
1213
import org.hibernate.testing.annotations.AnotherEntity;
1314
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1415
import org.hibernate.testing.orm.junit.Jpa;
1516
import org.hibernate.testing.orm.junit.RequiresDialect;
17+
import org.hibernate.testing.orm.junit.Setting;
1618
import org.junit.jupiter.api.AfterAll;
1719
import org.junit.jupiter.api.Assertions;
1820
import org.junit.jupiter.api.BeforeAll;
@@ -46,9 +48,7 @@ public void setup(EntityManagerFactoryScope scope) {
4648
@AfterAll
4749
public void tearDown(EntityManagerFactoryScope scope) {
4850
scope.inTransaction(
49-
entityManager -> {
50-
entityManager.createQuery( "delete from AnEntity" ).executeUpdate();
51-
}
51+
entityManager -> entityManager.createQuery( "delete from AnEntity" ).executeUpdate()
5252
);
5353
}
5454

@@ -67,7 +67,6 @@ public void nonAnnotatedMethodTest(EntityManagerFactoryScope scope) {
6767
Set<EntityType<?>> entities = scope.getEntityManagerFactory().getMetamodel().getEntities();
6868
assertEquals( 1, entities.size() );
6969
assertEquals( "AnEntity", entities.iterator().next().getName() );
70-
assertEquals( Boolean.FALSE, scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) );
7170
scope.inEntityManager(
7271
entityManager -> {
7372
AnEntity ae = entityManager.find( AnEntity.class, 1 );
@@ -80,7 +79,7 @@ public void nonAnnotatedMethodTest(EntityManagerFactoryScope scope) {
8079

8180
@Jpa(
8281
annotatedClasses = AnotherEntity.class,
83-
queryComplianceEnabled = true
82+
integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_QUERY_COMPLIANCE, value = "true")}
8483
)
8584
@Test
8685
public void annotatedMethodTest(EntityManagerFactoryScope scope) {
@@ -89,7 +88,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) {
8988
Set<EntityType<?>> entities = scope.getEntityManagerFactory().getMetamodel().getEntities();
9089
assertEquals( 1, entities.size() );
9190
assertEquals( "AnotherEntity", entities.iterator().next().getName() );
92-
assertEquals( Boolean.TRUE, scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) );
91+
assertEquals( "true", scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) );
9392
scope.inTransaction(
9493
entityManager -> {
9594
AnotherEntity aoe = new AnotherEntity( 2, "AnotherEntity_1" );
@@ -107,9 +106,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) {
107106
Assertions.assertThrows(
108107
IllegalArgumentException.class,
109108
() -> scope.inTransaction(
110-
entityManager -> {
111-
AnEntity ae = entityManager.find( AnEntity.class, 1 );
112-
}
109+
entityManager -> entityManager.find( AnEntity.class, 1 )
113110
)
114111
);
115112
}

hibernate-testing/src/test/java/org/hibernate/testing/annotations/methods/MoreEntityManagerFactoryScopeTesting.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
import java.util.Set;
88

9+
import org.hibernate.cfg.JpaComplianceSettings;
910
import org.hibernate.dialect.H2Dialect;
1011

1112
import org.hibernate.testing.annotations.AnEntity;
1213
import org.hibernate.testing.annotations.AnotherEntity;
1314
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1415
import org.hibernate.testing.orm.junit.Jpa;
1516
import org.hibernate.testing.orm.junit.RequiresDialect;
17+
import org.hibernate.testing.orm.junit.Setting;
1618
import org.junit.jupiter.api.Assertions;
1719
import org.junit.jupiter.api.Test;
1820

@@ -43,7 +45,7 @@ public void testBasicUsage(EntityManagerFactoryScope scope) {
4345

4446
@Jpa(
4547
annotatedClasses = AnotherEntity.class,
46-
queryComplianceEnabled = true
48+
integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_QUERY_COMPLIANCE, value = "true")}
4749
)
4850
@Test
4951
public void annotatedMethodTest(EntityManagerFactoryScope scope) {
@@ -52,7 +54,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) {
5254
Set<EntityType<?>> entities = scope.getEntityManagerFactory().getMetamodel().getEntities();
5355
assertEquals( 1, entities.size() );
5456
assertEquals( "AnotherEntity", entities.iterator().next().getName() );
55-
assertEquals( Boolean.TRUE, scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) );
57+
assertEquals( "true", scope.getEntityManagerFactory().getProperties().get( "hibernate.jpa.compliance.query" ) );
5658
scope.inTransaction(
5759
entityManager -> {
5860
AnotherEntity aoe = new AnotherEntity( 2, "AnotherEntity_1" );
@@ -70,9 +72,7 @@ public void annotatedMethodTest(EntityManagerFactoryScope scope) {
7072
Assertions.assertThrows(
7173
IllegalArgumentException.class,
7274
() -> scope.inTransaction(
73-
entityManager -> {
74-
AnEntity ae = entityManager.find( AnEntity.class, 1 );
75-
}
75+
entityManager -> entityManager.find( AnEntity.class, 1 )
7676
)
7777
);
7878
}

migration-guide.adoc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,39 @@ See the link:{releaseSeriesBase}#whats-new[website] for the list of new features
4141

4242
This section describes changes to contracts (classes, interfaces, methods, etc.) which are considered https://hibernate.org/community/compatibility-policy/#api[API].
4343

44+
[[jpa]]
45+
=== @Jpa (hibernate-testing)
46+
47+
The following methods have been removed from the `@Jpa` test utility, located in the hibernate-testing project:
48+
49+
- `jpaComplianceEnabled()`
50+
- `queryComplianceEnabled()`
51+
- `transactionComplianceEnabled()`
52+
- `closedComplianceEnabled()`
53+
- `orderByMappingComplianceEnabled()`
54+
- `proxyComplianceEnabled()`
55+
- `cacheComplianceEnabled()`
56+
- `generatorScopeComplianceEnabled()`
57+
- `loadByIdComplianceEnabled()`
58+
59+
The default value for these settings is still `false`.
60+
61+
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.
62+
63+
Example:
64+
65+
```
66+
@Jpa(annotatedClasses =
67+
...,
68+
integrationSettings = {
69+
// set all jpa compliance flags to true
70+
@Setting(name = JpaComplianceSettings.JPA_COMPLIANCE, value = "true"),
71+
// override or set a specific flag value to false
72+
@Setting(name = JpaComplianceSettings.JPA_PROXY_COMPLIANCE, value = "false")
73+
}
74+
)
75+
```
76+
4477

4578
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4679
// SPI changes

0 commit comments

Comments
 (0)