Skip to content

Commit 06fdd27

Browse files
scottmarlowdreab8
authored andcommitted
HHH-14196 Add parsing of persistence.xml/orm.xml documents in the EE 9 namespace
Signed-off-by: Scott Marlow <[email protected]>
1 parent 204dc9f commit 06fdd27

File tree

8 files changed

+2738
-4
lines changed

8 files changed

+2738
-4
lines changed

Diff for: hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/LocalXmlResourceResolver.java

+22
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public Object resolveEntity(String publicID, String systemID, String baseURI, St
4242
else if ( JPA_XSD_MAPPING.matches( namespace ) ) {
4343
return openUrlStream( JPA_XSD_MAPPING.getMappedLocalUrl() );
4444
}
45+
else if ( PERSISTENCE_ORM_XSD_MAPPING.matches( namespace ) ) {
46+
return openUrlStream( PERSISTENCE_ORM_XSD_MAPPING.getMappedLocalUrl() );
47+
}
48+
else if ( PERSISTENCE_ORM_XSD_MAPPING2.matches( namespace ) ) {
49+
return openUrlStream( PERSISTENCE_ORM_XSD_MAPPING2.getMappedLocalUrl() );
50+
}
4551
else if ( HBM_XSD_MAPPING.matches( namespace ) ) {
4652
return openUrlStream( HBM_XSD_MAPPING.getMappedLocalUrl() );
4753
}
@@ -152,7 +158,23 @@ private InputStream resolveInLocalNamespace(String path) {
152158
"http://xmlns.jcp.org/xml/ns/persistence/orm",
153159
"org/hibernate/jpa/orm_2_1.xsd"
154160
);
161+
162+
/**
163+
* Maps the namespace for the orm.xml xsd for Jakarta Persistence 2.2
164+
*/
165+
public static final NamespaceSchemaMapping PERSISTENCE_ORM_XSD_MAPPING = new NamespaceSchemaMapping(
166+
"http://xmlns.jcp.org/xml/ns/persistence/orm",
167+
"org/hibernate/jpa/orm_2_2.xsd"
168+
);
155169

170+
/**
171+
* Maps the namespace for the orm.xml xsd for Jakarta Persistence 3.0
172+
*/
173+
public static final NamespaceSchemaMapping PERSISTENCE_ORM_XSD_MAPPING2 = new NamespaceSchemaMapping(
174+
"https://jakarta.ee/xml/ns/persistence/orm",
175+
"org/hibernate/jpa/orm_3_0.xsd"
176+
);
177+
156178
public static final NamespaceSchemaMapping HBM_XSD_MAPPING = new NamespaceSchemaMapping(
157179
"http://www.hibernate.org/xsd/orm/hbm",
158180
"org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd"

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

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ private ConfigXsdSupport() {
5151
"http://xmlns.jcp.org/xml/ns/persistence"
5252
);
5353

54+
private final XsdDescriptor jpa30 = LocalXsdResolver.buildXsdDescriptor(
55+
"org/hibernate/jpa/persistence_3_0.xsd",
56+
"3.0",
57+
"https://jakarta.ee/xml/ns/persistence"
58+
);
59+
5460
private final XsdDescriptor cfgXml = LocalXsdResolver.buildXsdDescriptor(
5561
"org/hibernate/xsd/cfg/legacy-configuration-4.0.xsd",
5662
"4.0" ,
@@ -75,6 +81,9 @@ public XsdDescriptor jpaXsd(String version) {
7581
case "2.2": {
7682
return jpa22;
7783
}
84+
case "3.0": {
85+
return jpa30;
86+
}
7887
default: {
7988
throw new IllegalArgumentException( "Unrecognized JPA persistence.xml XSD version : `" + version + "`" );
8089
}

Diff for: hibernate-core/src/main/java/org/hibernate/boot/xsd/LocalXsdResolver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class LocalXsdResolver {
3535
private static final Logger log = Logger.getLogger( LocalXsdResolver.class );
3636

37-
private static final List<String> VALID_JPA_VERSIONS = Arrays.asList( "1.0", "2.0", "2.1", "2.2" );
37+
private static final List<String> VALID_JPA_VERSIONS = Arrays.asList( "1.0", "2.0", "2.1", "2.2", "3.0" );
3838

3939
public static String latestJpaVerison() {
4040
return "2.2";

Diff for: hibernate-core/src/main/java/org/hibernate/boot/xsd/MappingXsdSupport.java

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public class MappingXsdSupport {
4444
"http://xmlns.jcp.org/xml/ns/persistence"
4545
);
4646

47+
private final XsdDescriptor jpa30 = LocalXsdResolver.buildXsdDescriptor(
48+
"org/hibernate/jpa/orm_3_0.xsd",
49+
"3.0",
50+
"https://jakarta.ee/xml/ns/persistence/orm"
51+
);
52+
4753
private final XsdDescriptor hbmXml = LocalXsdResolver.buildXsdDescriptor(
4854
"org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd",
4955
"4.0",
@@ -72,6 +78,9 @@ public XsdDescriptor jpaXsd(String version) {
7278
case "2.2": {
7379
return jpa22;
7480
}
81+
case "3.0:": {
82+
return jpa30;
83+
}
7584
default: {
7685
throw new IllegalArgumentException( "Unrecognized JPA orm.xml XSD version : `" + version + "`" );
7786
}

Diff for: hibernate-core/src/main/java/org/hibernate/cfg/EJB3DTDEntityResolver.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,27 @@ public boolean isResolved() {
4141
public InputSource resolveEntity(String publicId, String systemId) {
4242
LOG.tracev( "Resolving XML entity {0} : {1}", publicId, systemId );
4343
if ( systemId != null ) {
44-
if ( systemId.endsWith( "orm_2_1.xsd" ) ) {
44+
if ( systemId.endsWith( "orm_3_0.xsd" ) ) {
45+
InputStream dtdStream = getStreamFromClasspath( "orm_3_0.xsd" );
46+
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
47+
if ( source != null ) {
48+
return source;
49+
}
50+
}
51+
else if ( systemId.endsWith( "orm_2_1.xsd" ) ) {
4552
InputStream dtdStream = getStreamFromClasspath( "orm_2_1.xsd" );
4653
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
4754
if ( source != null ) {
4855
return source;
4956
}
5057
}
58+
else if ( systemId.endsWith( "orm_2_2.xsd" ) ) {
59+
InputStream dtdStream = getStreamFromClasspath( "orm_2_2.xsd" );
60+
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
61+
if ( source != null ) {
62+
return source;
63+
}
64+
}
5165
else if ( systemId.endsWith( "orm_2_0.xsd" ) ) {
5266
InputStream dtdStream = getStreamFromClasspath( "orm_2_0.xsd" );
5367
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
@@ -62,6 +76,20 @@ else if ( systemId.endsWith( "orm_1_0.xsd" ) ) {
6276
return source;
6377
}
6478
}
79+
else if ( systemId.endsWith( "persistence_3_0.xsd" ) ) {
80+
InputStream dtdStream = getStreamFromClasspath( "persistence_3_0.xsd" );
81+
final InputSource source = buildInputSource( publicId, systemId, dtdStream, true );
82+
if ( source != null ) {
83+
return source;
84+
}
85+
}
86+
else if ( systemId.endsWith( "persistence_2_2.xsd" ) ) {
87+
InputStream dtdStream = getStreamFromClasspath( "persistence_2_2.xsd" );
88+
final InputSource source = buildInputSource( publicId, systemId, dtdStream, true );
89+
if ( source != null ) {
90+
return source;
91+
}
92+
}
6593
else if ( systemId.endsWith( "persistence_2_1.xsd" ) ) {
6694
InputStream dtdStream = getStreamFromClasspath( "persistence_2_1.xsd" );
6795
final InputSource source = buildInputSource( publicId, systemId, dtdStream, true );

0 commit comments

Comments
 (0)