Merge remote-tracking branch 'upstream/master' into wip/6.0

This commit is contained in:
Andrea Boriero 2020-10-22 10:57:39 +01:00
commit 27c06efd66
11 changed files with 2766 additions and 22 deletions

View File

@ -42,6 +42,12 @@ public class LocalXmlResourceResolver implements javax.xml.stream.XMLResolver {
else if ( JPA_XSD_MAPPING.matches( namespace ) ) {
return openUrlStream( JPA_XSD_MAPPING.getMappedLocalUrl() );
}
else if ( PERSISTENCE_ORM_XSD_MAPPING.matches( namespace ) ) {
return openUrlStream( PERSISTENCE_ORM_XSD_MAPPING.getMappedLocalUrl() );
}
else if ( PERSISTENCE_ORM_XSD_MAPPING2.matches( namespace ) ) {
return openUrlStream( PERSISTENCE_ORM_XSD_MAPPING2.getMappedLocalUrl() );
}
else if ( HBM_XSD_MAPPING.matches( namespace ) ) {
return openUrlStream( HBM_XSD_MAPPING.getMappedLocalUrl() );
}
@ -152,7 +158,23 @@ public class LocalXmlResourceResolver implements javax.xml.stream.XMLResolver {
"http://xmlns.jcp.org/xml/ns/persistence/orm",
"org/hibernate/jpa/orm_2_1.xsd"
);
/**
* Maps the namespace for the orm.xml xsd for Jakarta Persistence 2.2
*/
public static final NamespaceSchemaMapping PERSISTENCE_ORM_XSD_MAPPING = new NamespaceSchemaMapping(
"http://xmlns.jcp.org/xml/ns/persistence/orm",
"org/hibernate/jpa/orm_2_2.xsd"
);
/**
* Maps the namespace for the orm.xml xsd for Jakarta Persistence 3.0
*/
public static final NamespaceSchemaMapping PERSISTENCE_ORM_XSD_MAPPING2 = new NamespaceSchemaMapping(
"https://jakarta.ee/xml/ns/persistence/orm",
"org/hibernate/jpa/orm_3_0.xsd"
);
public static final NamespaceSchemaMapping HBM_XSD_MAPPING = new NamespaceSchemaMapping(
"http://www.hibernate.org/xsd/orm/hbm",
"org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd"

View File

@ -26,9 +26,10 @@ public class ConfigXsdSupport {
* 1: JPA 1.0
* 2: JPA 2.0
* 3: JPA 2.1
* 4: JPA 2.2
* 4: JPA 2.2 (default)
* 5: Jakarta Persistence 3.0
*/
private static final XsdDescriptor[] xsdCache = new XsdDescriptor[5];
private static final XsdDescriptor[] xsdCache = new XsdDescriptor[6];
public XsdDescriptor latestJpaDescriptor() {
return getJPA22();
@ -48,6 +49,9 @@ public class ConfigXsdSupport {
case "2.2": {
return getJPA22();
}
case "3.0": {
return getJPA30();
}
default: {
throw new IllegalArgumentException( "Unrecognized JPA persistence.xml XSD version : `" + version + "`" );
}
@ -134,4 +138,20 @@ public class ConfigXsdSupport {
}
}
private XsdDescriptor getJPA30() {
final int index = 5;
synchronized ( xsdCache ) {
XsdDescriptor jpa30 = xsdCache[index];
if ( jpa30 == null ) {
jpa30 = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/jpa/persistence_3_0.xsd",
"3.0",
"https://jakarta.ee/xml/ns/persistence"
);
xsdCache[index] = jpa30;
}
return jpa30;
}
}
}

View File

@ -41,6 +41,7 @@ public class LocalXsdResolver {
case "2.0":
case "2.1":
case "2.2":
case "3.0":
return true;
default:
return false;

View File

@ -44,6 +44,12 @@ public class MappingXsdSupport {
"http://xmlns.jcp.org/xml/ns/persistence"
);
private final XsdDescriptor jpa30 = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/jpa/orm_3_0.xsd",
"3.0",
"https://jakarta.ee/xml/ns/persistence/orm"
);
private final XsdDescriptor hbmXml = LocalXsdResolver.buildXsdDescriptor(
"org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd",
"4.0",
@ -72,6 +78,9 @@ public class MappingXsdSupport {
case "2.2": {
return jpa22;
}
case "3.0:": {
return jpa30;
}
default: {
throw new IllegalArgumentException( "Unrecognized JPA orm.xml XSD version : `" + version + "`" );
}

View File

@ -41,13 +41,27 @@ public class EJB3DTDEntityResolver extends DTDEntityResolver {
public InputSource resolveEntity(String publicId, String systemId) {
LOG.tracev( "Resolving XML entity {0} : {1}", publicId, systemId );
if ( systemId != null ) {
if ( systemId.endsWith( "orm_2_1.xsd" ) ) {
if ( systemId.endsWith( "orm_3_0.xsd" ) ) {
InputStream dtdStream = getStreamFromClasspath( "orm_3_0.xsd" );
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
if ( source != null ) {
return source;
}
}
else if ( systemId.endsWith( "orm_2_1.xsd" ) ) {
InputStream dtdStream = getStreamFromClasspath( "orm_2_1.xsd" );
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
if ( source != null ) {
return source;
}
}
else if ( systemId.endsWith( "orm_2_2.xsd" ) ) {
InputStream dtdStream = getStreamFromClasspath( "orm_2_2.xsd" );
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
if ( source != null ) {
return source;
}
}
else if ( systemId.endsWith( "orm_2_0.xsd" ) ) {
InputStream dtdStream = getStreamFromClasspath( "orm_2_0.xsd" );
final InputSource source = buildInputSource( publicId, systemId, dtdStream, false );
@ -62,6 +76,20 @@ public class EJB3DTDEntityResolver extends DTDEntityResolver {
return source;
}
}
else if ( systemId.endsWith( "persistence_3_0.xsd" ) ) {
InputStream dtdStream = getStreamFromClasspath( "persistence_3_0.xsd" );
final InputSource source = buildInputSource( publicId, systemId, dtdStream, true );
if ( source != null ) {
return source;
}
}
else if ( systemId.endsWith( "persistence_2_2.xsd" ) ) {
InputStream dtdStream = getStreamFromClasspath( "persistence_2_2.xsd" );
final InputSource source = buildInputSource( publicId, systemId, dtdStream, true );
if ( source != null ) {
return source;
}
}
else if ( systemId.endsWith( "persistence_2_1.xsd" ) ) {
InputStream dtdStream = getStreamFromClasspath( "persistence_2_1.xsd" );
final InputSource source = buildInputSource( publicId, systemId, dtdStream, true );

View File

@ -152,7 +152,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
return new JdbcEnvironmentImpl( registry, dialect, dbmd );
}
catch (SQLException e) {
log.unableToObtainConnectionMetadata( e.getMessage() );
log.unableToObtainConnectionMetadata( e );
}
finally {
try {
@ -163,7 +163,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
}
}
catch (Exception e) {
log.unableToObtainConnectionToQueryMetadata( e.getMessage() );
log.unableToObtainConnectionToQueryMetadata( e );
}
}

View File

@ -1131,19 +1131,11 @@ public interface CoreMessageLogger extends BasicLogger {
@LogMessage(level = WARN)
@Message(value = "Could not obtain connection metadata: %s", id = 339)
void unableToObjectConnectionMetadata(SQLException error);
void unableToObtainConnectionMetadata(SQLException error);
@LogMessage(level = WARN)
@Message(value = "Could not obtain connection to query metadata: %s", id = 340)
void unableToObjectConnectionToQueryMetadata(SQLException error);
@LogMessage(level = WARN)
@Message(value = "Could not obtain connection metadata : %s", id = 341)
void unableToObtainConnectionMetadata(String message);
@LogMessage(level = WARN)
@Message(value = "Could not obtain connection to query metadata : %s", id = 342)
void unableToObtainConnectionToQueryMetadata(String message);
@Message(value = "Could not obtain connection to query metadata", id = 342)
void unableToObtainConnectionToQueryMetadata(@Cause Exception e);
@LogMessage(level = ERROR)
@Message(value = "Could not obtain initial context", id = 343)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,342 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0,
or the Eclipse Distribution License v. 1.0 which is available at
http://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
-->
<!-- persistence.xml schema -->
<xsd:schema targetNamespace="https://jakarta.ee/xml/ns/persistence"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:persistence="https://jakarta.ee/xml/ns/persistence"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="3.0">
<xsd:annotation>
<xsd:documentation><![CDATA[
This is the XML Schema for the persistence configuration file.
The file must be named "META-INF/persistence.xml" in the
persistence archive.
Persistence configuration files must indicate
the persistence schema by using the persistence namespace:
https://jakarta.ee/xml/ns/persistence
and indicate the version of the schema by
using the version element as shown below:
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
...
</persistence>
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType name="versionType">
<xsd:restriction base="xsd:token">
<xsd:pattern value="[0-9]+(\.[0-9]+)*"/>
</xsd:restriction>
</xsd:simpleType>
<!-- **************************************************** -->
<xsd:element name="persistence">
<xsd:complexType>
<xsd:sequence>
<!-- **************************************************** -->
<xsd:element name="persistence-unit"
minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Configuration of a persistence unit.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<!-- **************************************************** -->
<xsd:element name="description" type="xsd:string"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Description of this persistence unit.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="provider" type="xsd:string"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Provider class that supplies EntityManagers for this
persistence unit.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="jta-data-source" type="xsd:string"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
The container-specific name of the JTA datasource to use.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="non-jta-data-source" type="xsd:string"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
The container-specific name of a non-JTA datasource to use.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="mapping-file" type="xsd:string"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
File containing mapping information. Loaded as a resource
by the persistence provider.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="jar-file" type="xsd:string"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Jar file that is to be scanned for managed classes.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="class" type="xsd:string"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Managed class to be included in the persistence unit and
to scan for annotations. It should be annotated
with either @Entity, @Embeddable or @MappedSuperclass.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="exclude-unlisted-classes" type="xsd:boolean"
default="true" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
When set to true then only listed classes and jars will
be scanned for persistent classes, otherwise the
enclosing jar or directory will also be scanned.
Not applicable to Java SE persistence units.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="shared-cache-mode"
type="persistence:persistence-unit-caching-type"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Defines whether caching is enabled for the
persistence unit if caching is supported by the
persistence provider. When set to ALL, all entities
will be cached. When set to NONE, no entities will
be cached. When set to ENABLE_SELECTIVE, only entities
specified as cacheable will be cached. When set to
DISABLE_SELECTIVE, entities specified as not cacheable
will not be cached. When not specified or when set to
UNSPECIFIED, provider defaults may apply.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="validation-mode"
type="persistence:persistence-unit-validation-mode-type"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
The validation mode to be used for the persistence unit.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- **************************************************** -->
<xsd:element name="properties" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
A list of standard and vendor-specific properties
and hints.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="property"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
A name-value pair.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string"
use="required"/>
<xsd:attribute name="value" type="xsd:string"
use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<!-- **************************************************** -->
<xsd:attribute name="name" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
Name used in code to reference this persistence unit.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<!-- **************************************************** -->
<xsd:attribute name="transaction-type"
type="persistence:persistence-unit-transaction-type">
<xsd:annotation>
<xsd:documentation>
Type of transactions used by EntityManagers from this
persistence unit.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="version" type="persistence:versionType"
fixed="3.0" use="required"/>
</xsd:complexType>
</xsd:element>
<!-- **************************************************** -->
<xsd:simpleType name="persistence-unit-transaction-type">
<xsd:annotation>
<xsd:documentation>
public enum PersistenceUnitTransactionType {JTA, RESOURCE_LOCAL};
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:token">
<xsd:enumeration value="JTA"/>
<xsd:enumeration value="RESOURCE_LOCAL"/>
</xsd:restriction>
</xsd:simpleType>
<!-- **************************************************** -->
<xsd:simpleType name="persistence-unit-caching-type">
<xsd:annotation>
<xsd:documentation>
public enum SharedCacheMode { ALL, NONE, ENABLE_SELECTIVE, DISABLE_SELECTIVE, UNSPECIFIED};
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:token">
<xsd:enumeration value="ALL"/>
<xsd:enumeration value="NONE"/>
<xsd:enumeration value="ENABLE_SELECTIVE"/>
<xsd:enumeration value="DISABLE_SELECTIVE"/>
<xsd:enumeration value="UNSPECIFIED"/>
</xsd:restriction>
</xsd:simpleType>
<!-- **************************************************** -->
<xsd:simpleType name="persistence-unit-validation-mode-type">
<xsd:annotation>
<xsd:documentation>
public enum ValidationMode { AUTO, CALLBACK, NONE};
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:token">
<xsd:enumeration value="AUTO"/>
<xsd:enumeration value="CALLBACK"/>
<xsd:enumeration value="NONE"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

View File

@ -12,7 +12,9 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
@ -22,6 +24,11 @@ import org.junit.Test;
* @author Nathan Xu
*/
@TestForIssue( jiraKey = "HHH-14234" )
@RequiresDialect(
value = H2Dialect.class,
comment = "This test relies on 'hibernate.hbm2ddl.halt_on_error', only tested on h2; " +
"other dialects might be broken due to irrelevant reason (e.g. not supporting 'if exists' while dropping tables)."
)
public class DenormalizedTablePhysicalIncludedTableConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
@Override
@ -40,13 +47,12 @@ public class DenormalizedTablePhysicalIncludedTableConstraintTest extends BaseNo
@Test
public void testUniqueConstraintFromSupTableNotAppliedToSubTable() {
// Unique constraint should be unique in db
// Without fixing, exception will be thrown when unique constraint in 'SUPTABLE' is applied to 'SUBTABLE' as well
// Both table names are uppercase to accommodate HANA dialect (see https://stackoverflow.com/questions/29974507/sap-hana-invalid-table-name)
// Without fixing, exception will be thrown when unique constraint in 'supTable' is applied to 'subTable' as well
}
@Entity(name = "SuperClass")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table( name = "SUPTABLE",
@Table( name = "supTable",
uniqueConstraints = {
@UniqueConstraint( name = "UK",
columnNames = {"colOne", "colTwo"})
@ -66,7 +72,7 @@ public class DenormalizedTablePhysicalIncludedTableConstraintTest extends BaseNo
}
@Entity(name = "SubClass")
@Table( name = "SUBTABLE" )
@Table( name = "subTable" )
static class SubClass extends SuperClass {
@Column(name = "colThree")

View File

@ -9,7 +9,7 @@
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="3.0"
version="2020"
>
<!-- use orm_1_0 on purpose (backward compatibility test -->
<package>org.hibernate.test.annotations.xml.ejb3</package>
@ -24,4 +24,4 @@
<basic name="power"></basic>
</attributes>
</entity>
</entity-mappings>
</entity-mappings>