Skip to content

Commit 95fc0bf

Browse files
committed
HHH-17377 - Migrate to JPA 3.2
https://hibernate.atlassian.net/browse/HHH-17377 JPA 3.2 B02
1 parent 8296662 commit 95fc0bf

File tree

12 files changed

+341
-319
lines changed

12 files changed

+341
-319
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.boot.jaxb.cfg.internal;
8+
9+
import org.hibernate.internal.util.StringHelper;
10+
11+
import jakarta.persistence.SharedCacheMode;
12+
import jakarta.persistence.spi.PersistenceUnitTransactionType;
13+
14+
/**
15+
* @author Steve Ebersole
16+
*/
17+
public class SharedCacheModeMarshalling {
18+
public static SharedCacheMode fromXml(String name) {
19+
if ( StringHelper.isEmpty( name ) ) {
20+
return SharedCacheMode.UNSPECIFIED;
21+
}
22+
return SharedCacheMode.valueOf( name );
23+
}
24+
25+
public static String toXml(SharedCacheMode sharedCacheMode) {
26+
if ( sharedCacheMode == null ) {
27+
return null;
28+
}
29+
return sharedCacheMode.name();
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.boot.jaxb.cfg.internal;
8+
9+
import org.hibernate.internal.util.StringHelper;
10+
11+
import jakarta.persistence.AccessType;
12+
import jakarta.persistence.spi.PersistenceUnitTransactionType;
13+
14+
/**
15+
* @author Steve Ebersole
16+
*/
17+
public class TransactionTypeMarshalling {
18+
public static PersistenceUnitTransactionType fromXml(String name) {
19+
if ( StringHelper.isEmpty( name ) ) {
20+
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
21+
}
22+
return PersistenceUnitTransactionType.valueOf( name );
23+
}
24+
25+
public static String toXml(PersistenceUnitTransactionType transactionType) {
26+
if ( transactionType == null ) {
27+
return null;
28+
}
29+
return transactionType.name();
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.boot.jaxb.cfg.internal;
8+
9+
import org.hibernate.internal.util.StringHelper;
10+
11+
import jakarta.persistence.SharedCacheMode;
12+
import jakarta.persistence.ValidationMode;
13+
14+
/**
15+
* @author Steve Ebersole
16+
*/
17+
public class ValidationModeMarshalling {
18+
public static ValidationMode fromXml(String name) {
19+
if ( StringHelper.isEmpty( name ) ) {
20+
return ValidationMode.AUTO;
21+
}
22+
return ValidationMode.valueOf( name );
23+
}
24+
25+
public static String toXml(ValidationMode validationMode) {
26+
if ( validationMode == null ) {
27+
return null;
28+
}
29+
return validationMode.name();
30+
}
31+
}

hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/AbstractEventReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,16 @@ private Iterator<Namespace> existingXmlNamespacesIterator(StartElement startElem
146146
}
147147

148148
private Namespace mapNamespace(Namespace originalNamespace) {
149-
if ( XsdHelper.shouldBeMappedToLatestJpaDescriptor( originalNamespace.getNamespaceURI() ) ) {
149+
if ( shouldBeMappedToLatestJpaDescriptor( originalNamespace.getNamespaceURI() ) ) {
150150
// this is a namespace "to map" so map it
151151
return xmlEventFactory.createNamespace( originalNamespace.getPrefix(), xsdDescriptor.getNamespaceUri() );
152152
}
153153

154154
return originalNamespace;
155155
}
156156

157+
protected abstract boolean shouldBeMappedToLatestJpaDescriptor(String uri);
158+
157159
private XMLEvent wrap(EndElement endElement) {
158160
final List<Namespace> targetNamespaces = mapNamespaces( existingXmlNamespacesIterator( endElement ) );
159161

hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/ConfigurationEventReader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ public class ConfigurationEventReader extends AbstractEventReader {
2020
public ConfigurationEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory) {
2121
super(
2222
ROOT_ELEMENT_NAME,
23-
ConfigXsdSupport.getJPA32(),
23+
ConfigXsdSupport.configurationXsd(),
2424
reader,
2525
xmlEventFactory
2626
);
2727
}
28+
29+
@Override
30+
protected boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
31+
return !ConfigXsdSupport.configurationXsd().getNamespaceUri().equals( uri );
32+
}
2833
}

hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/MappingEventReader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ public MappingEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory
2424
super( ROOT_ELEMENT_NAME, MappingXsdSupport.latestDescriptor(), reader, xmlEventFactory );
2525
}
2626

27+
@Override
28+
protected boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
29+
return !MappingXsdSupport.latestDescriptor().getNamespaceUri().equals( uri );
30+
}
2731
}

hibernate-core/src/main/java/org/hibernate/boot/xsd/ConfigXsdSupport.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ public XsdDescriptor latestJpaDescriptor() {
4141
}
4242

4343
public static boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
44-
// JPA 1.0 and 2.0 share the same namespace URI
45-
return getJPA10().getNamespaceUri().matches( uri );
44+
// Any namespace prior to move to Jakarta (3.0) needs to be remapped
45+
// NOTE:
46+
// - JPA 1.0 and 2.0 share the same namespace URI
47+
// - JPA 2.1 and 2.2 share the same namespace URI
48+
return !configurationXsd().getNamespaceUri().equals( uri );
49+
4650
}
4751

4852
public XsdDescriptor jpaXsd(String version) {

hibernate-core/src/main/java/org/hibernate/boot/xsd/XsdHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static boolean isValidJpaVersion(String version) {
1919

2020
public static boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
2121
// JPA 1.0 and 2.0 share the same namespace URI
22+
// JPA 2.1 and 2.2 share the same namespace URI
2223
return MappingXsdSupport.jpa10.getNamespaceUri().equals( uri );
2324
}
2425
}

hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/ParsedPersistenceXmlDescriptor.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
import java.net.URL;
1010
import java.util.ArrayList;
1111
import java.util.Arrays;
12-
import java.util.Collection;
13-
import java.util.Collections;
1412
import java.util.List;
1513
import java.util.Properties;
16-
import jakarta.persistence.SharedCacheMode;
17-
import jakarta.persistence.ValidationMode;
18-
import jakarta.persistence.spi.PersistenceUnitTransactionType;
1914

15+
import org.hibernate.boot.archive.internal.ArchiveHelper;
2016
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
2117
import org.hibernate.bytecode.spi.ClassTransformer;
2218

19+
import jakarta.persistence.SharedCacheMode;
20+
import jakarta.persistence.ValidationMode;
21+
import jakarta.persistence.spi.PersistenceUnitTransactionType;
22+
2323
/**
2424
* Describes the information gleaned from a {@code <persistence-unit/>} element in a {@code persistence.xml} file
2525
* whether parsed directly by Hibernate or passed to us by an EE container as a
@@ -130,17 +130,25 @@ public ValidationMode getValidationMode() {
130130
return validationMode;
131131
}
132132

133+
public void setValidationMode(ValidationMode validationMode) {
134+
this.validationMode = validationMode;
135+
}
136+
133137
public void setValidationMode(String validationMode) {
134-
this.validationMode = ValidationMode.valueOf( validationMode );
138+
setValidationMode( ValidationMode.valueOf( validationMode ) );
135139
}
136140

137141
@Override
138142
public SharedCacheMode getSharedCacheMode() {
139143
return sharedCacheMode;
140144
}
141145

146+
public void setSharedCacheMode(SharedCacheMode sharedCacheMode) {
147+
this.sharedCacheMode = sharedCacheMode;
148+
}
149+
142150
public void setSharedCacheMode(String sharedCacheMode) {
143-
this.sharedCacheMode = SharedCacheMode.valueOf( sharedCacheMode );
151+
setSharedCacheMode( SharedCacheMode.valueOf( sharedCacheMode ) );
144152
}
145153

146154
@Override
@@ -178,6 +186,12 @@ public void addJarFileUrl(URL jarFileUrl) {
178186
jarFileUrls.add( jarFileUrl );
179187
}
180188

189+
public void addJarFileUrls(List<String> jarFiles) {
190+
jarFiles.forEach( (jarFile) -> {
191+
addJarFileUrl( ArchiveHelper.getURLFromPath( jarFile ) );
192+
} );
193+
}
194+
181195
@Override
182196
public ClassLoader getClassLoader() {
183197
return null;

0 commit comments

Comments
 (0)