diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 553b83c530..2509d1295f 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -84,7 +84,7 @@ task jaxb { // input schemas cfgXsd = file( 'src/main/resources/org/hibernate/hibernate-configuration-4.0.xsd') hbmXsd = file( 'src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd' ) - ormXsd = file( 'src/main/resources/org/hibernate/ejb/orm_2_0.xsd' ) + ormXsd = file( 'src/main/resources/org/hibernate/jpa/orm_2_0.xsd' ) // input bindings cfgXjb = file( 'src/main/xjb/hbm-configuration-bindings.xjb' ) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/EJB3DTDEntityResolver.java b/hibernate-core/src/main/java/org/hibernate/cfg/EJB3DTDEntityResolver.java index 4eff1d24bb..78d21b3148 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/EJB3DTDEntityResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/EJB3DTDEntityResolver.java @@ -56,37 +56,57 @@ public class EJB3DTDEntityResolver extends DTDEntityResolver { @Override public InputSource resolveEntity(String publicId, String systemId) { LOG.tracev( "Resolving XML entity {0} : {1}", publicId, systemId ); - InputSource is = super.resolveEntity( publicId, systemId ); - if ( is == null ) { - if ( systemId != null ) { - if ( systemId.endsWith( "orm_1_0.xsd" ) ) { - InputStream dtdStream = getStreamFromClasspath( "orm_1_0.xsd" ); - final InputSource source = buildInputSource( publicId, systemId, dtdStream, false ); - if (source != null) return source; + if ( systemId != null ) { + 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_0.xsd" ) ) { - InputStream dtdStream = getStreamFromClasspath( "orm_2_0.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 ); + if ( source != null ) { + return source; } - else if ( systemId.endsWith( "persistence_1_0.xsd" ) ) { - InputStream dtdStream = getStreamFromClasspath( "persistence_1_0.xsd" ); - final InputSource source = buildInputSource( publicId, systemId, dtdStream, true ); - if (source != null) return source; + } + else if ( systemId.endsWith( "orm_1_0.xsd" ) ) { + InputStream dtdStream = getStreamFromClasspath( "orm_1_0.xsd" ); + final InputSource source = buildInputSource( publicId, systemId, dtdStream, false ); + if ( source != null ) { + return source; } - else if ( systemId.endsWith( "persistence_2_0.xsd" ) ) { - InputStream dtdStream = getStreamFromClasspath( "persistence_2_0.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 ); + if ( source != null ) { + return source; + } + } + else if ( systemId.endsWith( "persistence_2_0.xsd" ) ) { + InputStream dtdStream = getStreamFromClasspath( "persistence_2_0.xsd" ); + final InputSource source = buildInputSource( publicId, systemId, dtdStream, true ); + if ( source != null ) { + return source; + } + } + else if ( systemId.endsWith( "persistence_1_0.xsd" ) ) { + InputStream dtdStream = getStreamFromClasspath( "persistence_1_0.xsd" ); + final InputSource source = buildInputSource( publicId, systemId, dtdStream, true ); + if ( source != null ) { + return source; } } } - else { + + // because the old code did this too (in terms of setting resolved) + InputSource source = super.resolveEntity( publicId, systemId ); + if ( source != null ) { resolved = true; - return is; } - //use the default behavior - return null; + return source; } private InputSource buildInputSource(String publicId, String systemId, InputStream dtdStream, boolean resolved) { @@ -103,8 +123,8 @@ public class EJB3DTDEntityResolver extends DTDEntityResolver { } private InputStream getStreamFromClasspath(String fileName) { - LOG.trace( "Recognized JPA ORM namespace; attempting to resolve on classpath under org/hibernate/ejb" ); - String path = "org/hibernate/ejb/" + fileName; + LOG.trace( "Recognized JPA ORM namespace; attempting to resolve on classpath under org/hibernate/jpa" ); + String path = "org/hibernate/jpa/" + fileName; InputStream dtdStream = resolveInHibernateNamespace( path ); return dtdStream; } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/ErrorLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/ErrorLogger.java index acbb0762a2..fceacce7f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/ErrorLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/ErrorLogger.java @@ -58,9 +58,7 @@ public class ErrorLogger implements ErrorHandler, Serializable { this.file = file; } - /** - * {@inheritDoc} - */ + @Override public void error(SAXParseException error) { if ( this.errors == null ) { errors = new ArrayList(); @@ -68,23 +66,16 @@ public class ErrorLogger implements ErrorHandler, Serializable { errors.add( error ); } - /** - * {@inheritDoc} - */ + @Override public void fatalError(SAXParseException error) { error( error ); } - /** - * {@inheritDoc} - */ + @Override public void warning(SAXParseException warn) { LOG.parsingXmlWarning( warn.getLineNumber(), warn.getMessage() ); } - /** - * @return returns a list of encountered xml parsing errors, or the empty list if there was no error - */ public List getErrors() { return errors; } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/MappingReader.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/MappingReader.java index d40e2b3eb4..3312d9dfb6 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/MappingReader.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/MappingReader.java @@ -23,17 +23,30 @@ */ package org.hibernate.internal.util.xml; -import java.io.StringReader; +import javax.xml.XMLConstants; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.dom.DOMDocumentFactory; import org.dom4j.io.SAXReader; -import org.jboss.logging.Logger; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.jboss.logging.Logger; + import org.hibernate.InvalidMappingException; +import org.hibernate.MappingException; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.ConfigHelper; /** * Handles reading mapping documents, both {@code hbm} and {@code orm} varieties. @@ -42,11 +55,13 @@ import org.hibernate.internal.CoreMessageLogger; */ public class MappingReader { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( + private static final CoreMessageLogger log = Logger.getMessageLogger( CoreMessageLogger.class, MappingReader.class.getName() ); + public static final String ASSUMED_ORM_XSD_VERSION = "2.1"; + public static final MappingReader INSTANCE = new MappingReader(); /** @@ -59,70 +74,70 @@ public class MappingReader { private MappingReader() { } - public XmlDocument readMappingDocument(EntityResolver entityResolver, InputSource source, Origin origin) { - // IMPL NOTE : this is the legacy logic as pulled from the old AnnotationConfiguration code - - Exception failure; - ErrorLogger errorHandler = new ErrorLogger(); - - SAXReader saxReader = new SAXReader(); - saxReader.setEntityResolver( entityResolver ); - saxReader.setErrorHandler( errorHandler ); - saxReader.setMergeAdjacentText( true ); - saxReader.setValidation( true ); - - Document document = null; - try { - // first try with orm 2.0 xsd validation - setValidationFor( saxReader, "orm_2_0.xsd" ); - document = saxReader.read( source ); - if ( errorHandler.hasErrors() ) { - throw errorHandler.getErrors().get( 0 ); - } - return new XmlDocumentImpl( document, origin.getType(), origin.getName() ); - } - catch ( Exception orm2Problem ) { - if ( LOG.isDebugEnabled() ) { - LOG.debugf( "Problem parsing XML using orm 2 xsd : %s", orm2Problem.getMessage() ); - } - failure = orm2Problem; - errorHandler.reset(); - - if ( document != null ) { - // next try with orm 1.0 xsd validation - try { - setValidationFor( saxReader, "orm_1_0.xsd" ); - document = saxReader.read( new StringReader( document.asXML() ) ); - if ( errorHandler.hasErrors() ) { - errorHandler.logErrors(); - throw errorHandler.getErrors().get( 0 ); - } - return new XmlDocumentImpl( document, origin.getType(), origin.getName() ); - } - catch ( Exception orm1Problem ) { - if ( LOG.isDebugEnabled() ) { - LOG.debugf( "Problem parsing XML using orm 1 xsd : %s", orm1Problem.getMessage() ); - } - } - } - } - throw new InvalidMappingException( "Unable to read XML", origin.getType(), origin.getName(), failure ); - } - - private void setValidationFor(SAXReader saxReader, String xsd) { - try { - saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true ); - //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true ); - //set the default schema locators - saxReader.setProperty( - "http://apache.org/xml/properties/schema/external-schemaLocation", - "http://java.sun.com/xml/ns/persistence/orm " + xsd - ); - } - catch ( SAXException e ) { - saxReader.setValidation( false ); - } - } +// public XmlDocument readMappingDocument(EntityResolver entityResolver, InputSource source, Origin origin) { +// // IMPL NOTE : this is the legacy logic as pulled from the old AnnotationConfiguration code +// +// Exception failure; +// ErrorLogger errorHandler = new ErrorLogger(); +// +// SAXReader saxReader = new SAXReader(); +// saxReader.setEntityResolver( entityResolver ); +// saxReader.setErrorHandler( errorHandler ); +// saxReader.setMergeAdjacentText( true ); +// saxReader.setValidation( true ); +// +// Document document = null; +// try { +// // first try with orm 2.0 xsd validation +// setValidationFor( saxReader, "orm_2_0.xsd" ); +// document = saxReader.read( source ); +// if ( errorHandler.hasErrors() ) { +// throw errorHandler.getErrors().get( 0 ); +// } +// return new XmlDocumentImpl( document, origin.getType(), origin.getName() ); +// } +// catch ( Exception orm2Problem ) { +// if ( LOG.isDebugEnabled() ) { +// LOG.debugf( "Problem parsing XML using orm 2 xsd : %s", orm2Problem.getMessage() ); +// } +// failure = orm2Problem; +// errorHandler.reset(); +// +// if ( document != null ) { +// // next try with orm 1.0 xsd validation +// try { +// setValidationFor( saxReader, "orm_1_0.xsd" ); +// document = saxReader.read( new StringReader( document.asXML() ) ); +// if ( errorHandler.hasErrors() ) { +// errorHandler.logErrors(); +// throw errorHandler.getErrors().get( 0 ); +// } +// return new XmlDocumentImpl( document, origin.getType(), origin.getName() ); +// } +// catch ( Exception orm1Problem ) { +// if ( LOG.isDebugEnabled() ) { +// LOG.debugf( "Problem parsing XML using orm 1 xsd : %s", orm1Problem.getMessage() ); +// } +// } +// } +// } +// throw new InvalidMappingException( "Unable to read XML", origin.getType(), origin.getName(), failure ); +// } +// +// private void setValidationFor(SAXReader saxReader, String xsd) { +// try { +// saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true ); +// //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true ); +// //set the default schema locators +// saxReader.setProperty( +// "http://apache.org/xml/properties/schema/external-schemaLocation", +// "http://java.sun.com/xml/ns/persistence/orm " + xsd +// ); +// } +// catch ( SAXException e ) { +// saxReader.setValidation( false ); +// } +// } // this is the version of the code I'd like to use, but it unfortunately works very differently between // JDK 1.5 ad JDK 1.6. On 1.5 the vaildation "passes" even with invalid content. @@ -132,134 +147,131 @@ public class MappingReader { // 2) Document the issue on 1.5 and how to fix (specifying alternate SchemaFactory instance) // 3) Use a specific JAXP library (Xerces2, Saxon, Jing, MSV) and its SchemaFactory instance directly -// public XmlDocument readMappingDocument(EntityResolver entityResolver, InputSource source, Origin origin) { -// ErrorLogger errorHandler = new ErrorLogger(); -// -// SAXReader saxReader = new SAXReader( new DOMDocumentFactory() ); -// saxReader.setEntityResolver( entityResolver ); -// saxReader.setErrorHandler( errorHandler ); -// saxReader.setMergeAdjacentText( true ); -// -// Document documentTree = null; -// -// // IMPL NOTE : here we enable DTD validation in case the mapping is a HBM file. This will validate -// // the document as it is parsed. This is needed because the DTD defines default values that have to be -// // applied as the document is parsed, so thats something we need to account for as we (if we) transition -// // to XSD. -// saxReader.setValidation( true ); -// try { -// documentTree = saxReader.read( source ); -// } -// catch ( DocumentException e ) { -// // we had issues reading the input, most likely malformed document or validation error against DTD -// throw new InvalidMappingException( "Unable to read XML", origin.getType(), origin.getName(), e ); -// } -// -// Element rootElement = documentTree.getRootElement(); -// if ( rootElement == null ) { -// throw new InvalidMappingException( "No root element", origin.getType(), origin.getName() ); -// } -// -// if ( "entity-mappings".equals( rootElement.getName() ) ) { -// final String explicitVersion = rootElement.attributeValue( "version" ); -// final String xsdVersionString = explicitVersion == null ? ASSUMED_ORM_XSD_VERSION : explicitVersion; -// final SupportedOrmXsdVersion xsdVersion = SupportedOrmXsdVersion.parse( xsdVersionString ); -// final Schema schema = xsdVersion == SupportedOrmXsdVersion.ORM_1_0 ? orm1Schema() : orm2Schema(); -// try { -// schema.newValidator().validate( new DOMSource( (org.w3c.dom.Document) documentTree ) ); -// } -// catch ( SAXException e ) { -// throw new InvalidMappingException( "Validation problem", origin.getType(), origin.getName(), e ); -// } -// catch ( IOException e ) { -// throw new InvalidMappingException( "Validation problem", origin.getType(), origin.getName(), e ); -// } -// } -// else { -// if ( errorHandler.getError() != null ) { -// throw new InvalidMappingException( -// "Error validating hibernate-mapping against DTD", -// origin.getType(), -// origin.getName(), -// errorHandler.getError() -// ); -// } -// } -// -// return new XmlDocumentImpl( documentTree, origin ); -// } -// -// public static enum SupportedOrmXsdVersion { -// ORM_1_0, -// ORM_2_0; -// -// public static SupportedOrmXsdVersion parse(String name) { -// if ( "1.0".equals( name ) ) { -// return ORM_1_0; -// } -// else if ( "2.0".equals( name ) ) { -// return ORM_2_0; -// } -// throw new IllegalArgumentException( "Unsupported orm.xml XSD version encountered [" + name + "]" ); -// } -// } -// -// -// public static final String ORM_1_SCHEMA_NAME = "org/hibernate/ejb/orm_1_0.xsd"; -// public static final String ORM_2_SCHEMA_NAME = "org/hibernate/ejb/orm_2_0.xsd"; -// -// private static Schema orm1Schema; -// -// private static Schema orm1Schema() { -// if ( orm1Schema == null ) { -// orm1Schema = resolveLocalSchema( ORM_1_SCHEMA_NAME ); -// } -// return orm1Schema; -// } -// -// private static Schema orm2Schema; -// -// private static Schema orm2Schema() { -// if ( orm2Schema == null ) { -// orm2Schema = resolveLocalSchema( ORM_2_SCHEMA_NAME ); -// } -// return orm2Schema; -// } -// -// private static Schema resolveLocalSchema(String schemaName) { -// return resolveLocalSchema( schemaName, XMLConstants.W3C_XML_SCHEMA_NS_URI ); -// } -// -// private static Schema resolveLocalSchema(String schemaName, String schemaLanguage) { -// URL url = ConfigHelper.findAsResource( schemaName ); -// if ( url == null ) { -// throw new MappingException( "Unable to locate schema [" + schemaName + "] via classpath" ); -// } -// try { -// InputStream schemaStream = url.openStream(); -// try { -// StreamSource source = new StreamSource(url.openStream()); -// SchemaFactory schemaFactory = SchemaFactory.newInstance( schemaLanguage ); -// return schemaFactory.newSchema(source); -// } -// catch ( SAXException e ) { -// throw new MappingException( "Unable to load schema [" + schemaName + "]", e ); -// } -// catch ( IOException e ) { -// throw new MappingException( "Unable to load schema [" + schemaName + "]", e ); -// } -// finally { -// try { -// schemaStream.close(); -// } -// catch ( IOException e ) { -// log.warn( "Problem closing schema stream [{}]", e.toString() ); -// } -// } -// } -// catch ( IOException e ) { -// throw new MappingException( "Stream error handling schema url [" + url.toExternalForm() + "]" ); -// } -// -// } + public XmlDocument readMappingDocument(EntityResolver entityResolver, InputSource source, Origin origin) { + ErrorLogger errorHandler = new ErrorLogger(); + + SAXReader saxReader = new SAXReader( new DOMDocumentFactory() ); + saxReader.setEntityResolver( entityResolver ); + saxReader.setErrorHandler( errorHandler ); + saxReader.setMergeAdjacentText( true ); + + Document documentTree; + + // IMPL NOTE : here we enable DTD validation in case the mapping is a HBM file. This will validate + // the document as it is parsed. This is needed because the DTD defines default values that have to be + // applied as the document is parsed, so thats something we need to account for as we (if we) transition + // to XSD. + saxReader.setValidation( true ); + try { + documentTree = saxReader.read( source ); + } + catch ( DocumentException e ) { + // we had issues reading the input, most likely malformed document or validation error against DTD + throw new InvalidMappingException( "Unable to read XML", origin.getType(), origin.getName(), e ); + } + + Element rootElement = documentTree.getRootElement(); + if ( rootElement == null ) { + throw new InvalidMappingException( "No root element", origin.getType(), origin.getName() ); + } + + if ( "entity-mappings".equals( rootElement.getName() ) ) { + final String explicitVersion = rootElement.attributeValue( "version" ); + final String xsdVersionString = explicitVersion == null ? ASSUMED_ORM_XSD_VERSION : explicitVersion; + final SupportedOrmXsdVersion xsdVersion = SupportedOrmXsdVersion.parse( xsdVersionString, origin ); + final Schema schema = xsdVersion.getSchema(); + try { + schema.newValidator().validate( new DOMSource( (org.w3c.dom.Document) documentTree ) ); + } + catch ( SAXException e ) { + throw new InvalidMappingException( "Validation problem", origin.getType(), origin.getName(), e ); + } + catch ( IOException e ) { + throw new InvalidMappingException( "Validation problem", origin.getType(), origin.getName(), e ); + } + } + else { + if ( errorHandler.hasErrors() ) { + errorHandler.logErrors(); + errorHandler.reset(); + throw new InvalidMappingException( + "Error validating hibernate-mapping against DTD; see logs for details", + origin.getType(), + origin.getName() + ); + } + } + + return new XmlDocumentImpl( documentTree, origin ); + } + + public static enum SupportedOrmXsdVersion { + ORM_1_0( "org/hibernate/jpa/orm_1_0.xsd" ), + ORM_2_0( "org/hibernate/jpa/orm_2_0.xsd"), + ORM_2_1( "org/hibernate/jpa/orm_2_1.xsd"); + + private final String schemaResourceName; + private Schema schema; + + private SupportedOrmXsdVersion(String schemaResourceName) { + this.schemaResourceName = schemaResourceName; + } + + public static SupportedOrmXsdVersion parse(String name, Origin origin) { + if ( "1.0".equals( name ) ) { + return ORM_1_0; + } + else if ( "2.0".equals( name ) ) { + return ORM_2_0; + } + else if ( "2.1".equals( name ) ) { + return ORM_2_1; + } + throw new UnsupportedOrmXsdVersionException( name, origin ); + } + + public Schema getSchema() { + if ( schema == null ) { + schema = resolveLocalSchema( schemaResourceName ); + } + return schema; + } + } + + private static Schema resolveLocalSchema(String schemaName) { + return resolveLocalSchema( schemaName, XMLConstants.W3C_XML_SCHEMA_NS_URI ); + } + + private static Schema resolveLocalSchema(String schemaName, String schemaLanguage) { + URL url = ConfigHelper.findAsResource( schemaName ); + if ( url == null ) { + throw new MappingException( "Unable to locate schema [" + schemaName + "] via classpath" ); + } + try { + InputStream schemaStream = url.openStream(); + try { + StreamSource source = new StreamSource(url.openStream()); + SchemaFactory schemaFactory = SchemaFactory.newInstance( schemaLanguage ); + return schemaFactory.newSchema(source); + } + catch ( SAXException e ) { + throw new MappingException( "Unable to load schema [" + schemaName + "]", e ); + } + catch ( IOException e ) { + throw new MappingException( "Unable to load schema [" + schemaName + "]", e ); + } + finally { + try { + schemaStream.close(); + } + catch ( IOException e ) { + log.debugf( "Problem closing schema stream - %s", e.toString() ); + } + } + } + catch ( IOException e ) { + throw new MappingException( "Stream error handling schema url [" + url.toExternalForm() + "]" ); + } + + } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/UnsupportedOrmXsdVersionException.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/UnsupportedOrmXsdVersionException.java new file mode 100644 index 0000000000..f57b590a30 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/UnsupportedOrmXsdVersionException.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.internal.util.xml; + +import org.hibernate.InvalidMappingException; + +/** + * @author Steve Ebersole + */ +public class UnsupportedOrmXsdVersionException extends InvalidMappingException { + public UnsupportedOrmXsdVersionException(String version, Origin origin) { + super( "Encountered unsupported orm.xml xsd version [" + version + "]", origin.getType(), origin.getName() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/JaxbHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/JaxbHelper.java index 1e56b113d1..5b24cec9e2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/JaxbHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/JaxbHelper.java @@ -216,8 +216,8 @@ public class JaxbHelper { } public static final String HBM_SCHEMA_NAME = "org/hibernate/hibernate-mapping-4.0.xsd"; - public static final String ORM_1_SCHEMA_NAME = "org/hibernate/ejb/orm_1_0.xsd"; - public static final String ORM_2_SCHEMA_NAME = "org/hibernate/ejb/orm_2_0.xsd"; + public static final String ORM_1_SCHEMA_NAME = "org/hibernate/jpa/orm_1_0.xsd"; + public static final String ORM_2_SCHEMA_NAME = "org/hibernate/jpa/orm_2_0.xsd"; private Schema hbmSchema; diff --git a/hibernate-core/src/main/resources/org/hibernate/ejb/orm_1_0.xsd b/hibernate-core/src/main/resources/org/hibernate/jpa/orm_1_0.xsd similarity index 97% rename from hibernate-core/src/main/resources/org/hibernate/ejb/orm_1_0.xsd rename to hibernate-core/src/main/resources/org/hibernate/jpa/orm_1_0.xsd index c21e996c4a..55d3517623 100644 --- a/hibernate-core/src/main/resources/org/hibernate/ejb/orm_1_0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/jpa/orm_1_0.xsd @@ -1,1540 +1,1540 @@ - - - - - - - - - @(#)orm_1_0.xsd 1.0 Feb 14 2006 - - - - - - - - - - - - - - - - - - - - - - The entity-mappings element is the root element of an mapping - file. It contains the following four types of elements: - - 1. The persistence-unit-metadata element contains metadata - for the entire persistence unit. It is undefined if this element - occurs in multiple mapping files within the same persistence unit. - - 2. The package, schema, catalog and access elements apply to all of - the entity, mapped-superclass and embeddable elements defined in - the same file in which they occur. - - 3. The sequence-generator, table-generator, named-query, - named-native-query and sql-result-set-mapping elements are global - to the persistence unit. It is undefined to have more than one - sequence-generator or table-generator of the same name in the same - or different mapping files in a persistence unit. It is also - undefined to have more than one named-query or named-native-query - of the same name in the same or different mapping files in a - persistence unit. - - 4. The entity, mapped-superclass and embeddable elements each define - the mapping information for a managed persistent class. The mapping - information contained in these elements may be complete or it may - be partial. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Metadata that applies to the persistence unit and not just to - the mapping file in which it is contained. - - If the xml-mapping-metadata-complete element is specified then - the complete set of mapping metadata for the persistence unit - is contained in the XML mapping files for the persistence unit. - - - - - - - - - - - - - - - - These defaults are applied to the persistence unit as a whole - unless they are overridden by local annotation or XML - element settings. - - schema - Used as the schema for all tables or secondary tables - that apply to the persistence unit - catalog - Used as the catalog for all tables or secondary tables - that apply to the persistence unit - access - Used as the access type for all managed classes in - the persistence unit - cascade-persist - Adds cascade-persist to the set of cascade options - in entity relationships of the persistence unit - entity-listeners - List of default entity listeners to be invoked - on each entity in the persistence unit. - - - - - - - - - - - - - - - - - - - Defines the settings and mappings for an entity. Is allowed to be - sparsely populated and used in conjunction with the annotations. - Alternatively, the metadata-complete attribute can be used to - indicate that no annotations on the entity class (and its fields - or properties) are to be processed. If this is the case then - the defaulting rules for the entity and its subelements will - be recursively applied. - - @Target(TYPE) @Retention(RUNTIME) - public @interface Entity { - String name() default ""; - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This element contains the entity field or property mappings. - It may be sparsely populated to include only a subset of the - fields or properties. If metadata-complete for the entity is true - then the remainder of the attributes will be defaulted according - to the default rules. - - - - - - - - - - - - - - - - - - - - - - - - - - This element determines how the persistence provider accesses the - state of an entity or embedded object. - - - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface EntityListeners { - Class[] value(); - } - - - - - - - - - - - - - - - Defines an entity listener to be invoked at lifecycle events - for the entities that list this listener. - - - - - - - - - - - - - - - - - - - - - - @Target({METHOD}) @Retention(RUNTIME) - public @interface PrePersist {} - - - - - - - - - - - - - @Target({METHOD}) @Retention(RUNTIME) - public @interface PostPersist {} - - - - - - - - - - - - - @Target({METHOD}) @Retention(RUNTIME) - public @interface PreRemove {} - - - - - - - - - - - - - @Target({METHOD}) @Retention(RUNTIME) - public @interface PostRemove {} - - - - - - - - - - - - - @Target({METHOD}) @Retention(RUNTIME) - public @interface PreUpdate {} - - - - - - - - - - - - - @Target({METHOD}) @Retention(RUNTIME) - public @interface PostUpdate {} - - - - - - - - - - - - - @Target({METHOD}) @Retention(RUNTIME) - public @interface PostLoad {} - - - - - - - - - - - - - @Target({}) @Retention(RUNTIME) - public @interface QueryHint { - String name(); - String value(); - } - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface NamedQuery { - String name(); - String query(); - QueryHint[] hints() default {}; - } - - - - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface NamedNativeQuery { - String name(); - String query(); - QueryHint[] hints() default {}; - Class resultClass() default void.class; - String resultSetMapping() default ""; //named SqlResultSetMapping - } - - - - - - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface SqlResultSetMapping { - String name(); - EntityResult[] entities() default {}; - ColumnResult[] columns() default {}; - } - - - - - - - - - - - - - - - - - @Target({}) @Retention(RUNTIME) - public @interface EntityResult { - Class entityClass(); - FieldResult[] fields() default {}; - String discriminatorColumn() default ""; - } - - - - - - - - - - - - - - - - - @Target({}) @Retention(RUNTIME) - public @interface FieldResult { - String name(); - String column(); - } - - - - - - - - - - - - - - @Target({}) @Retention(RUNTIME) - public @interface ColumnResult { - String name(); - } - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface Table { - String name() default ""; - String catalog() default ""; - String schema() default ""; - UniqueConstraint[] uniqueConstraints() default {}; - } - - - - - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface SecondaryTable { - String name(); - String catalog() default ""; - String schema() default ""; - PrimaryKeyJoinColumn[] pkJoinColumns() default {}; - UniqueConstraint[] uniqueConstraints() default {}; - } - - - - - - - - - - - - - - - - - - - @Target({}) @Retention(RUNTIME) - public @interface UniqueConstraint { - String[] columnNames(); - } - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Column { - String name() default ""; - boolean unique() default false; - boolean nullable() default true; - boolean insertable() default true; - boolean updatable() default true; - String columnDefinition() default ""; - String table() default ""; - int length() default 255; - int precision() default 0; // decimal precision - int scale() default 0; // decimal scale - } - - - - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface JoinColumn { - String name() default ""; - String referencedColumnName() default ""; - boolean unique() default false; - boolean nullable() default true; - boolean insertable() default true; - boolean updatable() default true; - String columnDefinition() default ""; - String table() default ""; - } - - - - - - - - - - - - - - - - - - - - public enum GenerationType { TABLE, SEQUENCE, IDENTITY, AUTO }; - - - - - - - - - - - - - - - - - - @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) - public @interface AttributeOverride { - String name(); - Column column(); - } - - - - - - - - - - - - - - - - @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) - public @interface AssociationOverride { - String name(); - JoinColumn[] joinColumns(); - } - - - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface IdClass { - Class value(); - } - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Id {} - - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface EmbeddedId {} - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Transient {} - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Version {} - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Basic { - FetchType fetch() default EAGER; - boolean optional() default true; - } - - - - - - - - - - - - - - - - - - - - - - - public enum FetchType { LAZY, EAGER }; - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Lob {} - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Temporal { - TemporalType value(); - } - - - - - - - - - - - - - public enum TemporalType { - DATE, // java.sql.Date - TIME, // java.sql.Time - TIMESTAMP // java.sql.Timestamp - } - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Enumerated { - EnumType value() default ORDINAL; - } - - - - - - - - - - - - - public enum EnumType { - ORDINAL, - STRING - } - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface ManyToOne { - Class targetEntity() default void.class; - CascadeType[] cascade() default {}; - FetchType fetch() default EAGER; - boolean optional() default true; - } - - - - - - - - - - - - - - - - - - - - - - - public enum CascadeType { ALL, PERSIST, MERGE, REMOVE, REFRESH}; - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface OneToOne { - Class targetEntity() default void.class; - CascadeType[] cascade() default {}; - FetchType fetch() default EAGER; - boolean optional() default true; - String mappedBy() default ""; - } - - - - - - - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface OneToMany { - Class targetEntity() default void.class; - CascadeType[] cascade() default {}; - FetchType fetch() default LAZY; - String mappedBy() default ""; - } - - - - - - - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface JoinTable { - String name() default ""; - String catalog() default ""; - String schema() default ""; - JoinColumn[] joinColumns() default {}; - JoinColumn[] inverseJoinColumns() default {}; - UniqueConstraint[] uniqueConstraints() default {}; - } - - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface ManyToMany { - Class targetEntity() default void.class; - CascadeType[] cascade() default {}; - FetchType fetch() default LAZY; - String mappedBy() default ""; - } - - - - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface GeneratedValue { - GenerationType strategy() default AUTO; - String generator() default ""; - } - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface MapKey { - String name() default ""; - } - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface OrderBy { - String value() default ""; - } - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface Inheritance { - InheritanceType strategy() default SINGLE_TABLE; - } - - - - - - - - - - - - - public enum InheritanceType - { SINGLE_TABLE, JOINED, TABLE_PER_CLASS}; - - - - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface DiscriminatorValue { - String value(); - } - - - - - - - - - - - - - public enum DiscriminatorType { STRING, CHAR, INTEGER }; - - - - - - - - - - - - - - - - - @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) - public @interface PrimaryKeyJoinColumn { - String name() default ""; - String referencedColumnName() default ""; - String columnDefinition() default ""; - } - - - - - - - - - - - - - - - @Target({TYPE}) @Retention(RUNTIME) - public @interface DiscriminatorColumn { - String name() default "DTYPE"; - DiscriminatorType discriminatorType() default STRING; - String columnDefinition() default ""; - int length() default 31; - } - - - - - - - - - - - - - - - - Defines the settings and mappings for embeddable objects. Is - allowed to be sparsely populated and used in conjunction with - the annotations. Alternatively, the metadata-complete attribute - can be used to indicate that no annotations are to be processed - in the class. If this is the case then the defaulting rules will - be recursively applied. - - @Target({TYPE}) @Retention(RUNTIME) - public @interface Embeddable {} - - - - - - - - - - - - - - - - - - - - - - - - - - - - @Target({METHOD, FIELD}) @Retention(RUNTIME) - public @interface Embedded {} - - - - - - - - - - - - - - - - Defines the settings and mappings for a mapped superclass. Is - allowed to be sparsely populated and used in conjunction with - the annotations. Alternatively, the metadata-complete attribute - can be used to indicate that no annotations are to be processed - If this is the case then the defaulting rules will be recursively - applied. - - @Target(TYPE) @Retention(RUNTIME) - public @interface MappedSuperclass{} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) - public @interface SequenceGenerator { - String name(); - String sequenceName() default ""; - int initialValue() default 1; - int allocationSize() default 50; - } - - - - - - - - - - - - - - - - @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) - public @interface TableGenerator { - String name(); - String table() default ""; - String catalog() default ""; - String schema() default ""; - String pkColumnName() default ""; - String valueColumnName() default ""; - String pkColumnValue() default ""; - int initialValue() default 0; - int allocationSize() default 50; - UniqueConstraint[] uniqueConstraints() default {}; - } - - - - - - - - - - - - - - - - - - - - + + + + + + + + + @(#)orm_1_0.xsd 1.0 Feb 14 2006 + + + + + + + + + + + + + + + + + + + + + + The entity-mappings element is the root element of an mapping + file. It contains the following four types of elements: + + 1. The persistence-unit-metadata element contains metadata + for the entire persistence unit. It is undefined if this element + occurs in multiple mapping files within the same persistence unit. + + 2. The package, schema, catalog and access elements apply to all of + the entity, mapped-superclass and embeddable elements defined in + the same file in which they occur. + + 3. The sequence-generator, table-generator, named-query, + named-native-query and sql-result-set-mapping elements are global + to the persistence unit. It is undefined to have more than one + sequence-generator or table-generator of the same name in the same + or different mapping files in a persistence unit. It is also + undefined to have more than one named-query or named-native-query + of the same name in the same or different mapping files in a + persistence unit. + + 4. The entity, mapped-superclass and embeddable elements each define + the mapping information for a managed persistent class. The mapping + information contained in these elements may be complete or it may + be partial. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Metadata that applies to the persistence unit and not just to + the mapping file in which it is contained. + + If the xml-mapping-metadata-complete element is specified then + the complete set of mapping metadata for the persistence unit + is contained in the XML mapping files for the persistence unit. + + + + + + + + + + + + + + + + These defaults are applied to the persistence unit as a whole + unless they are overridden by local annotation or XML + element settings. + + schema - Used as the schema for all tables or secondary tables + that apply to the persistence unit + catalog - Used as the catalog for all tables or secondary tables + that apply to the persistence unit + access - Used as the access type for all managed classes in + the persistence unit + cascade-persist - Adds cascade-persist to the set of cascade options + in entity relationships of the persistence unit + entity-listeners - List of default entity listeners to be invoked + on each entity in the persistence unit. + + + + + + + + + + + + + + + + + + + Defines the settings and mappings for an entity. Is allowed to be + sparsely populated and used in conjunction with the annotations. + Alternatively, the metadata-complete attribute can be used to + indicate that no annotations on the entity class (and its fields + or properties) are to be processed. If this is the case then + the defaulting rules for the entity and its subelements will + be recursively applied. + + @Target(TYPE) @Retention(RUNTIME) + public @interface Entity { + String name() default ""; + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This element contains the entity field or property mappings. + It may be sparsely populated to include only a subset of the + fields or properties. If metadata-complete for the entity is true + then the remainder of the attributes will be defaulted according + to the default rules. + + + + + + + + + + + + + + + + + + + + + + + + + + This element determines how the persistence provider accesses the + state of an entity or embedded object. + + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface EntityListeners { + Class[] value(); + } + + + + + + + + + + + + + + + Defines an entity listener to be invoked at lifecycle events + for the entities that list this listener. + + + + + + + + + + + + + + + + + + + + + + @Target({METHOD}) @Retention(RUNTIME) + public @interface PrePersist {} + + + + + + + + + + + + + @Target({METHOD}) @Retention(RUNTIME) + public @interface PostPersist {} + + + + + + + + + + + + + @Target({METHOD}) @Retention(RUNTIME) + public @interface PreRemove {} + + + + + + + + + + + + + @Target({METHOD}) @Retention(RUNTIME) + public @interface PostRemove {} + + + + + + + + + + + + + @Target({METHOD}) @Retention(RUNTIME) + public @interface PreUpdate {} + + + + + + + + + + + + + @Target({METHOD}) @Retention(RUNTIME) + public @interface PostUpdate {} + + + + + + + + + + + + + @Target({METHOD}) @Retention(RUNTIME) + public @interface PostLoad {} + + + + + + + + + + + + + @Target({}) @Retention(RUNTIME) + public @interface QueryHint { + String name(); + String value(); + } + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface NamedQuery { + String name(); + String query(); + QueryHint[] hints() default {}; + } + + + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface NamedNativeQuery { + String name(); + String query(); + QueryHint[] hints() default {}; + Class resultClass() default void.class; + String resultSetMapping() default ""; //named SqlResultSetMapping + } + + + + + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface SqlResultSetMapping { + String name(); + EntityResult[] entities() default {}; + ColumnResult[] columns() default {}; + } + + + + + + + + + + + + + + + + + @Target({}) @Retention(RUNTIME) + public @interface EntityResult { + Class entityClass(); + FieldResult[] fields() default {}; + String discriminatorColumn() default ""; + } + + + + + + + + + + + + + + + + + @Target({}) @Retention(RUNTIME) + public @interface FieldResult { + String name(); + String column(); + } + + + + + + + + + + + + + + @Target({}) @Retention(RUNTIME) + public @interface ColumnResult { + String name(); + } + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface Table { + String name() default ""; + String catalog() default ""; + String schema() default ""; + UniqueConstraint[] uniqueConstraints() default {}; + } + + + + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface SecondaryTable { + String name(); + String catalog() default ""; + String schema() default ""; + PrimaryKeyJoinColumn[] pkJoinColumns() default {}; + UniqueConstraint[] uniqueConstraints() default {}; + } + + + + + + + + + + + + + + + + + + + @Target({}) @Retention(RUNTIME) + public @interface UniqueConstraint { + String[] columnNames(); + } + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Column { + String name() default ""; + boolean unique() default false; + boolean nullable() default true; + boolean insertable() default true; + boolean updatable() default true; + String columnDefinition() default ""; + String table() default ""; + int length() default 255; + int precision() default 0; // decimal precision + int scale() default 0; // decimal scale + } + + + + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface JoinColumn { + String name() default ""; + String referencedColumnName() default ""; + boolean unique() default false; + boolean nullable() default true; + boolean insertable() default true; + boolean updatable() default true; + String columnDefinition() default ""; + String table() default ""; + } + + + + + + + + + + + + + + + + + + + + public enum GenerationType { TABLE, SEQUENCE, IDENTITY, AUTO }; + + + + + + + + + + + + + + + + + + @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) + public @interface AttributeOverride { + String name(); + Column column(); + } + + + + + + + + + + + + + + + + @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) + public @interface AssociationOverride { + String name(); + JoinColumn[] joinColumns(); + } + + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface IdClass { + Class value(); + } + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Id {} + + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface EmbeddedId {} + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Transient {} + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Version {} + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Basic { + FetchType fetch() default EAGER; + boolean optional() default true; + } + + + + + + + + + + + + + + + + + + + + + + + public enum FetchType { LAZY, EAGER }; + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Lob {} + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Temporal { + TemporalType value(); + } + + + + + + + + + + + + + public enum TemporalType { + DATE, // java.sql.Date + TIME, // java.sql.Time + TIMESTAMP // java.sql.Timestamp + } + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Enumerated { + EnumType value() default ORDINAL; + } + + + + + + + + + + + + + public enum EnumType { + ORDINAL, + STRING + } + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface ManyToOne { + Class targetEntity() default void.class; + CascadeType[] cascade() default {}; + FetchType fetch() default EAGER; + boolean optional() default true; + } + + + + + + + + + + + + + + + + + + + + + + + public enum CascadeType { ALL, PERSIST, MERGE, REMOVE, REFRESH}; + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface OneToOne { + Class targetEntity() default void.class; + CascadeType[] cascade() default {}; + FetchType fetch() default EAGER; + boolean optional() default true; + String mappedBy() default ""; + } + + + + + + + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface OneToMany { + Class targetEntity() default void.class; + CascadeType[] cascade() default {}; + FetchType fetch() default LAZY; + String mappedBy() default ""; + } + + + + + + + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface JoinTable { + String name() default ""; + String catalog() default ""; + String schema() default ""; + JoinColumn[] joinColumns() default {}; + JoinColumn[] inverseJoinColumns() default {}; + UniqueConstraint[] uniqueConstraints() default {}; + } + + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface ManyToMany { + Class targetEntity() default void.class; + CascadeType[] cascade() default {}; + FetchType fetch() default LAZY; + String mappedBy() default ""; + } + + + + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface GeneratedValue { + GenerationType strategy() default AUTO; + String generator() default ""; + } + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface MapKey { + String name() default ""; + } + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface OrderBy { + String value() default ""; + } + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface Inheritance { + InheritanceType strategy() default SINGLE_TABLE; + } + + + + + + + + + + + + + public enum InheritanceType + { SINGLE_TABLE, JOINED, TABLE_PER_CLASS}; + + + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface DiscriminatorValue { + String value(); + } + + + + + + + + + + + + + public enum DiscriminatorType { STRING, CHAR, INTEGER }; + + + + + + + + + + + + + + + + + @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) + public @interface PrimaryKeyJoinColumn { + String name() default ""; + String referencedColumnName() default ""; + String columnDefinition() default ""; + } + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface DiscriminatorColumn { + String name() default "DTYPE"; + DiscriminatorType discriminatorType() default STRING; + String columnDefinition() default ""; + int length() default 31; + } + + + + + + + + + + + + + + + + Defines the settings and mappings for embeddable objects. Is + allowed to be sparsely populated and used in conjunction with + the annotations. Alternatively, the metadata-complete attribute + can be used to indicate that no annotations are to be processed + in the class. If this is the case then the defaulting rules will + be recursively applied. + + @Target({TYPE}) @Retention(RUNTIME) + public @interface Embeddable {} + + + + + + + + + + + + + + + + + + + + + + + + + + + + @Target({METHOD, FIELD}) @Retention(RUNTIME) + public @interface Embedded {} + + + + + + + + + + + + + + + + Defines the settings and mappings for a mapped superclass. Is + allowed to be sparsely populated and used in conjunction with + the annotations. Alternatively, the metadata-complete attribute + can be used to indicate that no annotations are to be processed + If this is the case then the defaulting rules will be recursively + applied. + + @Target(TYPE) @Retention(RUNTIME) + public @interface MappedSuperclass{} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) + public @interface SequenceGenerator { + String name(); + String sequenceName() default ""; + int initialValue() default 1; + int allocationSize() default 50; + } + + + + + + + + + + + + + + + + @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) + public @interface TableGenerator { + String name(); + String table() default ""; + String catalog() default ""; + String schema() default ""; + String pkColumnName() default ""; + String valueColumnName() default ""; + String pkColumnValue() default ""; + int initialValue() default 0; + int allocationSize() default 50; + UniqueConstraint[] uniqueConstraints() default {}; + } + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-core/src/main/resources/org/hibernate/ejb/orm_2_0.xsd b/hibernate-core/src/main/resources/org/hibernate/jpa/orm_2_0.xsd similarity index 100% rename from hibernate-core/src/main/resources/org/hibernate/ejb/orm_2_0.xsd rename to hibernate-core/src/main/resources/org/hibernate/jpa/orm_2_0.xsd diff --git a/hibernate-entitymanager/src/main/resources/org/hibernate/jpa/orm_2_1.xsd b/hibernate-core/src/main/resources/org/hibernate/jpa/orm_2_1.xsd similarity index 100% rename from hibernate-entitymanager/src/main/resources/org/hibernate/jpa/orm_2_1.xsd rename to hibernate-core/src/main/resources/org/hibernate/jpa/orm_2_1.xsd diff --git a/hibernate-core/src/main/xjb/orm-bindings.xjb b/hibernate-core/src/main/xjb/orm-bindings.xjb index 0a30ac387a..940eb3a86a 100644 --- a/hibernate-core/src/main/xjb/orm-bindings.xjb +++ b/hibernate-core/src/main/xjb/orm-bindings.xjb @@ -4,7 +4,7 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.1"> - + diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/AbstractMockerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/AbstractMockerTest.java index 0a47735ea3..4b9f23a999 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/AbstractMockerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/AbstractMockerTest.java @@ -50,8 +50,9 @@ import static org.junit.Assert.fail; * @author Strong Liu */ public abstract class AbstractMockerTest { - private static final String ORM1_MAPPING_XSD = "org/hibernate/ejb/orm_1_0.xsd"; - private static final String ORM2_MAPPING_XSD = "org/hibernate/ejb/orm_2_0.xsd"; + private static final String ORM1_MAPPING_XSD = "org/hibernate/jpa/orm_1_0.xsd"; + private static final String ORM2_MAPPING_XSD = "org/hibernate/jpa/orm_2_0.xsd"; + private IndexBuilder indexBuilder; private Index index; private ServiceRegistry serviceRegistry; 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 5c98e7fcfa..54382c0bb4 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 @@ -25,14 +25,15 @@ package org.hibernate.test.annotations.xml.ejb3; import java.io.InputStream; +import org.hibernate.cfg.Configuration; +import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException; + import org.junit.Test; -import org.hibernate.MappingException; -import org.hibernate.cfg.Configuration; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; @TestForIssue(jiraKey = "HHH-6271") public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase { @@ -44,14 +45,9 @@ public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase { InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFileName ); config.addInputStream( is ); config.buildMappings(); + fail( "Expecting failure due to unsupported xsd version" ); } - catch ( MappingException mappingException ) { - Throwable cause = mappingException.getCause(); - assertTrue( - cause.getMessage().contains( - "Value '3.0' of attribute 'version' of element 'entity-mappings' is not valid" - ) - ); + catch ( UnsupportedOrmXsdVersionException expected ) { } } } diff --git a/hibernate-core/src/test/resources/log4j.properties b/hibernate-core/src/test/resources/log4j.properties new file mode 100644 index 0000000000..686aae8fc2 --- /dev/null +++ b/hibernate-core/src/test/resources/log4j.properties @@ -0,0 +1,17 @@ +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + + +log4j.rootLogger=info, stdout + +log4j.logger.org.hibernate.tool.hbm2ddl=trace +log4j.logger.org.hibernate.testing.cache=debug + +# SQL Logging - HHH-6833 +log4j.logger.org.hibernate.SQL=debug + +log4j.logger.org.hibernate.hql.internal.ast=debug + +log4j.logger.org.hibernate.sql.ordering.antlr=debug \ No newline at end of file