Skip to content

Commit bf1ea31

Browse files
scottmarlowSanne
authored andcommitted
HHH-14196 Add parsing of persistence.xml/orm.xml documents in the EE 9 namespace
Signed-off-by: Scott Marlow <smarlow@redhat.com>
1 parent 54dae73 commit bf1ea31

File tree

8 files changed

+2751
-5
lines changed

8 files changed

+2751
-5
lines changed

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

Lines changed: 22 additions & 0 deletions
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"

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ public class ConfigXsdSupport {
2626
* 1: JPA 1.0
2727
* 2: JPA 2.0
2828
* 3: JPA 2.1
29-
* 4: JPA 2.2
29+
* 4: JPA 2.2 (default)
30+
* 5: Jakarta Persistence 3.0
3031
*/
31-
private static final XsdDescriptor[] xsdCache = new XsdDescriptor[5];
32+
private static final XsdDescriptor[] xsdCache = new XsdDescriptor[6];
3233

3334
public XsdDescriptor latestJpaDescriptor() {
3435
return getJPA22();
@@ -48,6 +49,9 @@ public XsdDescriptor jpaXsd(String version) {
4849
case "2.2": {
4950
return getJPA22();
5051
}
52+
case "3.0": {
53+
return getJPA30();
54+
}
5155
default: {
5256
throw new IllegalArgumentException( "Unrecognized JPA persistence.xml XSD version : `" + version + "`" );
5357
}
@@ -134,4 +138,20 @@ private XsdDescriptor getJPA22() {
134138
}
135139
}
136140

141+
private XsdDescriptor getJPA30() {
142+
final int index = 5;
143+
synchronized ( xsdCache ) {
144+
XsdDescriptor jpa30 = xsdCache[index];
145+
if ( jpa30 == null ) {
146+
jpa30 = LocalXsdResolver.buildXsdDescriptor(
147+
"org/hibernate/jpa/persistence_3_0.xsd",
148+
"3.0",
149+
"https://jakarta.ee/xml/ns/persistence"
150+
);
151+
xsdCache[index] = jpa30;
152+
}
153+
return jpa30;
154+
}
155+
}
156+
137157
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static boolean isValidJpaVersion(String version) {
4343
case "2.0":
4444
case "2.1":
4545
case "2.2":
46+
case "3.0":
4647
return true;
4748
default:
4849
return false;

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

Lines changed: 9 additions & 0 deletions
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
}

hibernate-core/src/main/java/org/hibernate/cfg/EJB3DTDEntityResolver.java

Lines changed: 29 additions & 1 deletion
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)