HHH-8344 metamodel JAXB processing should throw
UnsupportedOrmXsdVersionException
This commit is contained in:
parent
5d114797e1
commit
f81f12317d
|
@ -82,19 +82,9 @@ public class JaxbMappingProcessor extends AbstractJaxbProcessor{
|
||||||
final String elementName = event.asStartElement().getName().getLocalPart();
|
final String elementName = event.asStartElement().getName().getLocalPart();
|
||||||
final Schema validationSchema;
|
final Schema validationSchema;
|
||||||
if ( "entity-mappings".equals( elementName ) ) {
|
if ( "entity-mappings".equals( elementName ) ) {
|
||||||
// final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME );
|
final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME );
|
||||||
// final String explicitVersion = attribute == null ? null : attribute.getValue();
|
final String explicitVersion = attribute == null ? null : attribute.getValue();
|
||||||
// validationSchema = validateXml ? resolveSupportedOrmXsd( explicitVersion, origin ) : null;
|
validationSchema = validateXml ? resolveSupportedOrmXsd( explicitVersion, origin ) : null;
|
||||||
|
|
||||||
/**
|
|
||||||
* here we always use JPA 2.1 schema to do the validation, since the {@link LegacyJPAEventReader} already
|
|
||||||
* transform the legacy orm.xml to JPA 2.1 namespace and version.
|
|
||||||
*
|
|
||||||
* This may causing some problems, like a jpa 1.0 orm.xml has some element which only available in the later
|
|
||||||
* version, which is "invalid" but due to the fact of we're using the latest schema to do the validation, then
|
|
||||||
* it is "valid". don't know if this will cause any problem, but let's do it for now.
|
|
||||||
*/
|
|
||||||
validationSchema = validateXml ? MappingReader.SupportedOrmXsdVersion.ORM_2_1.getSchema() : null;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
validationSchema = validateXml ? MappingReader.SupportedOrmXsdVersion.HBM_4_0.getSchema() : null;
|
validationSchema = validateXml ? MappingReader.SupportedOrmXsdVersion.HBM_4_0.getSchema() : null;
|
||||||
|
@ -166,9 +156,24 @@ public class JaxbMappingProcessor extends AbstractJaxbProcessor{
|
||||||
}
|
}
|
||||||
|
|
||||||
private Schema resolveSupportedOrmXsd(String explicitVersion, Origin origin) {
|
private Schema resolveSupportedOrmXsd(String explicitVersion, Origin origin) {
|
||||||
|
|
||||||
if ( StringHelper.isEmpty( explicitVersion ) ) {
|
if ( StringHelper.isEmpty( explicitVersion ) ) {
|
||||||
return MappingReader.SupportedOrmXsdVersion.ORM_2_1.getSchema();
|
return MappingReader.SupportedOrmXsdVersion.ORM_2_1.getSchema();
|
||||||
}
|
}
|
||||||
return MappingReader.SupportedOrmXsdVersion.parse( explicitVersion, origin ).getSchema();
|
|
||||||
|
// Here we always use JPA 2.1 schema to do the validation, since the {@link LegacyJPAEventReader} already
|
||||||
|
// transforms the legacy orm.xml to JPA 2.1 namespace and version.
|
||||||
|
//
|
||||||
|
// This may cause some problems, like a jpa 1.0 orm.xml having some element which is only available in the later
|
||||||
|
// version. It is "invalid" but due to the fact we're using the latest schema to do the validation, then
|
||||||
|
// it is "valid". Don't know if this will cause any problems, but let's do it for now.
|
||||||
|
//
|
||||||
|
// However, still check for the validity of the version by calling #parse. If someone explicitly uses a value
|
||||||
|
// that doesn't exist, we still need to throw the exception.
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
MappingReader.SupportedOrmXsdVersion version = MappingReader.SupportedOrmXsdVersion.parse( explicitVersion, origin );
|
||||||
|
// return version.getSchema();
|
||||||
|
return MappingReader.SupportedOrmXsdVersion.ORM_2_1.getSchema();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.io.InputStream;
|
||||||
import org.hibernate.InvalidMappingException;
|
import org.hibernate.InvalidMappingException;
|
||||||
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -39,7 +38,6 @@ import org.junit.Test;
|
||||||
public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase {
|
public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testNonExistentOrmVersion() {
|
public void testNonExistentOrmVersion() {
|
||||||
try {
|
try {
|
||||||
MetadataSources sources = new MetadataSources( buildBootstrapServiceRegistry() );
|
MetadataSources sources = new MetadataSources( buildBootstrapServiceRegistry() );
|
||||||
|
|
|
@ -23,21 +23,19 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.xml.ejb3;
|
package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.byteman.BytemanHelper;
|
||||||
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.jboss.byteman.contrib.bmunit.BMRule;
|
import org.jboss.byteman.contrib.bmunit.BMRule;
|
||||||
import org.jboss.byteman.contrib.bmunit.BMRules;
|
import org.jboss.byteman.contrib.bmunit.BMRules;
|
||||||
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
|
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.byteman.BytemanHelper;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
@TestForIssue(jiraKey = "HHH-6271")
|
@TestForIssue(jiraKey = "HHH-6271")
|
||||||
@RunWith(BMUnitRunner.class)
|
@RunWith(BMUnitRunner.class)
|
||||||
public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
||||||
|
@ -55,12 +53,7 @@ public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
||||||
action = "countInvocation()",
|
action = "countInvocation()",
|
||||||
name = "testOrm1Support")
|
name = "testOrm1Support")
|
||||||
})
|
})
|
||||||
@FailureExpectedWithNewMetamodel // This doesn't actually work since this test class requires BMUnitRunner instead of
|
|
||||||
// CustomRunner. Thus, the if block below skips the test if the new metamodel is being used.
|
|
||||||
public void testOrm1Support() {
|
public void testOrm1Support() {
|
||||||
if ( isMetadataUsed ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// need to call buildSessionFactory, because this test is not using org.hibernate.testing.junit4.CustomRunner
|
// need to call buildSessionFactory, because this test is not using org.hibernate.testing.junit4.CustomRunner
|
||||||
buildSessionFactory();
|
buildSessionFactory();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue