Skip to content

Commit 7f8ddad

Browse files
committed
HHH-19914 - Don't ignore the JPA_COMPLIANCE setting in @jpa
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 8a56476 commit 7f8ddad

File tree

7 files changed

+49
-71
lines changed

7 files changed

+49
-71
lines changed

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

Lines changed: 4 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,8 @@
2527
JpaProxyComplianceEnabledTest.Provider.class,
2628
JpaProxyComplianceEnabledTest.TelephoneNumber.class,
2729
},
28-
proxyComplianceEnabled = true
30+
jpaComplianceEnabled = true,
31+
integrationSettings = {@Setting(name = JpaComplianceSettings.JPA_PROXY_COMPLIANCE, value = "true")}
2932
)
3033
@JiraKey("HHH-19476")
3134
public class JpaProxyComplianceEnabledTest {

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: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static void collectProperties(PersistenceUnitInfoImpl pui, Jpa jpa) {
100100
final Properties properties = pui.getProperties();
101101
properties.putAll( Environment.getProperties() );
102102
// JpaCompliance
103-
setJpaComplianceProperties( properties, jpa );
103+
properties.put( AvailableSettings.JPA_COMPLIANCE, jpa.jpaComplianceEnabled() ? "true" : "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 & 42 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;
@@ -68,46 +66,6 @@
6866
*/
6967
boolean jpaComplianceEnabled() default false;
7068

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-
11169
boolean excludeUnlistedClasses() default false;
11270

11371
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,36 @@ 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+
- `queryComplianceEnabled()`
50+
- `transactionComplianceEnabled()`
51+
- `closedComplianceEnabled()`
52+
- `orderByMappingComplianceEnabled()`
53+
- `proxyComplianceEnabled()`
54+
- `cacheComplianceEnabled()`
55+
- `generatorScopeComplianceEnabled()`
56+
- `loadByIdComplianceEnabled()`
57+
58+
The default value for these settings is still `false`, and the generic `jpaComplianceEnabled()` can still be used to turn all these flags on, when needed.
59+
60+
To indicate a specific flag setting, or to override the generic value that was set with `jpaComplianceEnabled()`, `@Jpa` 's `integrationSettings` array should be used.
61+
62+
Example:
63+
64+
```
65+
@Jpa(
66+
...,
67+
// set all jpa compliance flags to true
68+
jpaComplianceEnabled = true,
69+
// override or set a specific flag value to false
70+
integrationSettings = { @Setting(name = JpaComplianceSettings.JPA_PROXY_COMPLIANCE, value = "false") }
71+
)
72+
```
73+
4474

4575
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4676
// SPI changes

0 commit comments

Comments
 (0)