diff --git a/hibernate-core/src/main/java/org/hibernate/jaxb/internal/JaxbMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/jaxb/internal/JaxbMappingProcessor.java index 2ed6b88224..b3c7a20c23 100644 --- a/hibernate-core/src/main/java/org/hibernate/jaxb/internal/JaxbMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/jaxb/internal/JaxbMappingProcessor.java @@ -82,19 +82,9 @@ public class JaxbMappingProcessor extends AbstractJaxbProcessor{ final String elementName = event.asStartElement().getName().getLocalPart(); final Schema validationSchema; if ( "entity-mappings".equals( elementName ) ) { -// final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME ); -// final String explicitVersion = attribute == null ? null : attribute.getValue(); -// 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; + final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME ); + final String explicitVersion = attribute == null ? null : attribute.getValue(); + validationSchema = validateXml ? resolveSupportedOrmXsd( explicitVersion, origin ) : null; } else { 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) { + if ( StringHelper.isEmpty( explicitVersion ) ) { 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(); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java index fd501f520e..da3cd4810c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java @@ -30,7 +30,6 @@ import java.io.InputStream; import org.hibernate.InvalidMappingException; import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException; import org.hibernate.metamodel.MetadataSources; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -39,7 +38,6 @@ import org.junit.Test; public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase { @Test - @FailureExpectedWithNewMetamodel public void testNonExistentOrmVersion() { try { MetadataSources sources = new MetadataSources( buildBootstrapServiceRegistry() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java index d88ba734ce..bf0388dccc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java @@ -23,21 +23,19 @@ */ 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.BMRules; import org.jboss.byteman.contrib.bmunit.BMUnitRunner; import org.junit.Test; 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") @RunWith(BMUnitRunner.class) public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase { @@ -55,12 +53,7 @@ public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase { action = "countInvocation()", 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() { - if ( isMetadataUsed ) { - return; - } // need to call buildSessionFactory, because this test is not using org.hibernate.testing.junit4.CustomRunner buildSessionFactory();