HHH-8893 - Develop Hibernate mapping XSD extending the JPA mapping (orm) XSD;

HHH-8894 - Use an "upgrade" approach to validate and bind (JAXB) mapping XML - hbm-to-orm XSLT
This commit is contained in:
Steve Ebersole 2014-02-07 16:55:16 -06:00
parent 8fe16b3519
commit 24b377a774
21 changed files with 2324 additions and 201 deletions

View File

@ -112,15 +112,17 @@ task jaxb {
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/jpa/orm_2_1.xsd' )
unifiedOrmXsd = file( 'src/main/resources/org/hibernate/xsd/mapping/orm-2.1.0.xsd' )
// input bindings
cfgXjb = file( 'src/main/xjb/hbm-configuration-bindings.xjb' )
hbmXjb = file( 'src/main/xjb/hbm-mapping-bindings.xjb' )
ormXjb = file( 'src/main/xjb/orm-bindings.xjb' )
unifiedOrmXjb = file( 'src/main/xjb/mapping-bindings.xjb' )
}
// configure Gradle up-to-date checking
inputs.files( [cfgXsd, hbmXsd, ormXsd, cfgXjb, hbmXjb, ormXjb] )
inputs.files( [cfgXsd, hbmXsd, ormXsd, unifiedOrmXsd, cfgXjb, hbmXjb, ormXjb, unifiedOrmXjb] )
outputs.dir( jaxbTargetDir )
// perform actions
@ -160,6 +162,17 @@ task jaxb {
arg line: '-Xinheritance'
}
// unified mapping xsd
ant.xjc(
destdir: '${jaxbTargetDir}',
// package: 'org.hibernate.metamodel.spi.source.jaxb',
binding: 'src/main/xjb/mapping-bindings.xjb',
schema: unifiedOrmXsd.path,
extension: 'true'
) {
arg line: '-Xinheritance'
}
}
}

View File

@ -479,7 +479,7 @@ public class MetadataSources {
*/
public MetadataSources addDocument(Document document) {
final Origin origin = new Origin( SourceType.DOM, UNKNOWN_FILE_PATH );
BindResult bindResult = jaxbProcessor.unmarshal( document, origin );
BindResult bindResult = jaxbProcessor.bind( document, origin );
addJaxbRoot( bindResult );
return this;
}

View File

@ -0,0 +1,192 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.internal.source.hbm.transform;
import java.util.Date;
import org.hibernate.jaxb.spi.hbm.JaxbFilterDefElement;
import org.hibernate.jaxb.spi.hbm.JaxbFilterParamElement;
import org.hibernate.jaxb.spi.hbm.JaxbHibernateMapping;
import org.hibernate.jaxb.spi.hbm.JaxbIdentifierGeneratorElement;
import org.hibernate.jaxb.spi.hbm.JaxbImportElement;
import org.hibernate.jaxb.spi.hbm.JaxbMetaContainerElement;
import org.hibernate.jaxb.spi.hbm.JaxbMetaElement;
import org.hibernate.jaxb.spi.hbm.JaxbParamElement;
import org.hibernate.jaxb.spi.hbm.JaxbTypedefElement;
import org.hibernate.metamodel.spi.source.jaxb.JaxbEntityMappings;
import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmFilterDef;
import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmIdGeneratorDef;
import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmParam;
import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmToolingHint;
import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmTypeDef;
import org.hibernate.metamodel.spi.source.jaxb.JaxbPersistenceUnitMetadata;
/**
* Transforms a JAXB binding of a hbm.xml file into a unified orm.xml representation
*
* @author Steve Ebersole
*/
public class HbmXmlTransformer {
/**
* Singleton access
*/
public static final HbmXmlTransformer INSTANCE = new HbmXmlTransformer();
public JaxbEntityMappings transform(JaxbHibernateMapping hbmXmlMapping) {
final JaxbEntityMappings ormRoot = new JaxbEntityMappings();
ormRoot.setDescription(
"Hibernate orm.xml document auto-generated from legacy hbm.xml format via transformation " +
"(generated at " + new Date().toString() + ")"
);
final JaxbPersistenceUnitMetadata metadata = new JaxbPersistenceUnitMetadata();
ormRoot.setPersistenceUnitMetadata( metadata );
metadata.setDescription(
"Defines information which applies to the persistence unit overall, not just to this mapping file.\n\n" +
"This transformation only specifies xml-mapping-metadata-complete."
);
transferToolingHints( hbmXmlMapping, ormRoot );
ormRoot.setPackage( hbmXmlMapping.getPackage() );
ormRoot.setSchema( hbmXmlMapping.getSchema() );
ormRoot.setCatalog( hbmXmlMapping.getCatalog() );
ormRoot.setCustomAccess( hbmXmlMapping.getDefaultAccess() );
ormRoot.setDefaultCascade( hbmXmlMapping.getDefaultCascade() );
ormRoot.setAutoImport( hbmXmlMapping.isAutoImport() );
ormRoot.setDefaultLazy( hbmXmlMapping.isDefaultLazy() );
transferTypeDefs( hbmXmlMapping, ormRoot );
transferFilterDefs( hbmXmlMapping, ormRoot );
transferIdentifierGenerators( hbmXmlMapping, ormRoot );
transferImports( hbmXmlMapping, ormRoot );
// <xs:element name="resultset" type="resultset-element"/>
// <xs:group ref="query-or-sql-query"/>
// <xs:element name="fetch-profile" type="fetch-profile-element"/>
// <xs:element name="database-object" type="database-object-element"/>
// <xs:element name="class" type="class-element"/>
// <xs:element name="subclass" type="subclass-element"/>
// <xs:element name="joined-subclass" type="joined-subclass-element"/>
// <xs:element name="union-subclass" type="union-subclass-element"/>
return ormRoot;
}
private void transferToolingHints(JaxbMetaContainerElement hbmMetaContainer, JaxbEntityMappings entityMappings) {
if ( hbmMetaContainer.getMeta().isEmpty() ) {
return;
}
for ( JaxbMetaElement hbmMetaElement : hbmMetaContainer.getMeta() ) {
final JaxbHbmToolingHint toolingHint = new JaxbHbmToolingHint();
entityMappings.getToolingHint().add( toolingHint );
toolingHint.setName( hbmMetaElement.getName() );
toolingHint.setInheritable( hbmMetaElement.isInheritable() );
toolingHint.setValue( hbmMetaElement.getValue() );
}
}
private void transferTypeDefs(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) {
if ( hbmXmlMapping.getTypedef().isEmpty() ) {
return;
}
for ( JaxbTypedefElement hbmXmlTypeDef : hbmXmlMapping.getTypedef() ) {
final JaxbHbmTypeDef typeDef = new JaxbHbmTypeDef();
ormRoot.getTypeDef().add( typeDef );
typeDef.setName( hbmXmlTypeDef.getName() );
typeDef.setClazz( hbmXmlTypeDef.getClazz() );
if ( !hbmXmlTypeDef.getParam().isEmpty() ) {
for ( JaxbParamElement hbmParam : hbmXmlTypeDef.getParam() ) {
final JaxbHbmParam param = new JaxbHbmParam();
typeDef.getParam().add( param );
param.setName( hbmParam.getName() );
param.setValue( hbmParam.getValue() );
}
}
}
}
private void transferFilterDefs(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) {
if ( hbmXmlMapping.getFilterDef().isEmpty() ) {
return;
}
for ( JaxbFilterDefElement hbmFilterDef : hbmXmlMapping.getFilterDef() ) {
JaxbHbmFilterDef filterDef = new JaxbHbmFilterDef();
ormRoot.getFilterDef().add( filterDef );
filterDef.setName( hbmFilterDef.getName() );
boolean foundCondition = false;
for ( Object content : hbmFilterDef.getContent() ) {
if ( String.class.isInstance( content ) ) {
foundCondition = true;
filterDef.setCondition( (String) content );
}
else {
JaxbFilterParamElement hbmFilterParam = (JaxbFilterParamElement) content;
JaxbHbmFilterDef.JaxbFilterParam param = new JaxbHbmFilterDef.JaxbFilterParam();
filterDef.getFilterParam().add( param );
param.setName( hbmFilterParam.getParameterName() );
param.setType( hbmFilterParam.getParameterValueTypeName() );
}
}
if ( !foundCondition ) {
filterDef.setCondition( hbmFilterDef.getCondition() );
}
}
}
private void transferIdentifierGenerators(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) {
if ( hbmXmlMapping.getIdentifierGenerator().isEmpty() ) {
return;
}
for ( JaxbIdentifierGeneratorElement hbmGenerator : hbmXmlMapping.getIdentifierGenerator() ) {
final JaxbHbmIdGeneratorDef generatorDef = new JaxbHbmIdGeneratorDef();
ormRoot.getIdentifierGeneratorDef().add( generatorDef );
generatorDef.setName( hbmGenerator.getName() );
generatorDef.setClazz( hbmGenerator.getClazz() );
}
}
private void transferImports(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) {
if ( hbmXmlMapping.getImport().isEmpty() ) {
return;
}
for ( JaxbImportElement hbmImport : hbmXmlMapping.getImport() ) {
final JaxbEntityMappings.JaxbImport ormImport = new JaxbEntityMappings.JaxbImport();
ormRoot.getImport().add( ormImport );
ormImport.setClazz( hbmImport.getClazz() );
ormImport.setRename( hbmImport.getRename() );
}
}
}

View File

@ -0,0 +1,52 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.spi.source.jaxb;
import java.util.List;
/**
* Common interface for JAXB bindings which are containers of attributes.
*
* @author Strong Liu
* @author Steve Ebersole
*/
public interface AttributesContainer {
List<JaxbTransient> getTransient();
List<JaxbBasic> getBasic();
List<JaxbElementCollection> getElementCollection();
List<JaxbEmbedded> getEmbedded();
List<JaxbManyToMany> getManyToMany();
List<JaxbManyToOne> getManyToOne();
List<JaxbOneToMany> getOneToMany();
List<JaxbOneToOne> getOneToOne();
}

View File

@ -0,0 +1,34 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.spi.source.jaxb;
/**
* Common interface for all the JAXB bindings representing lifecycle callbacks.
*
* @author Strong Liu
* @author Steve Ebersole
*/
public interface LifecycleCallback {
public String getMethodName();
}

View File

@ -0,0 +1,42 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.spi.source.jaxb;
/**
* Common interface for JAXB bindings representing entities, mapped-superclasses and embeddables (JPA collective
* calls these "managed types" in terms of its Metamodel api).
*
* @author Strong Liu
* @author Steve Ebersole
*/
public interface ManagedType {
String getClazz();
void setClazz(String className);
Boolean isMetadataComplete();
void setMetadataComplete(Boolean isMetadataComplete);
public JaxbAccessType getAccess();
}

View File

@ -0,0 +1,33 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.spi.source.jaxb;
import java.util.List;
/**
* @author Steve Ebersole
*/
public interface Parameterized {
public List<JaxbHbmParam> getParam();
}

View File

@ -0,0 +1,42 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.spi.source.jaxb;
/**
* Common interface for JAXB bindings that represent persistent attributes.
*
* @author Strong Liu
* @author Steve Ebersole
*/
public interface PersistentAttribute {
String getName();
JaxbAccessType getAccess();
void setAccess(JaxbAccessType accessType);
String getCustomAccess();
void setCustomAccess(String customAccess);
}

View File

@ -0,0 +1,40 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.spi.source.jaxb;
/**
* Common interface for JAXB bindings that understand database schema (tables, sequences, etc).
*
* @author Strong Liu
* @author Steve Ebersole
*/
public interface SchemaAware {
String getSchema();
void setSchema(String schema);
String getCatalog();
void setCatalog(String catalog);
}

View File

@ -0,0 +1,35 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.metamodel.spi.source.jaxb;
import java.util.List;
/**
* Common interface for JAXB bindings which are containers of tooling hints.
*
* @author Steve Ebersole
*/
public interface ToolingHintContainer {
public List<JaxbHbmToolingHint> getToolingHint();
}

View File

@ -109,30 +109,29 @@ abstract class AbstractXmlBinder implements XmlBinder {
@SuppressWarnings( { "unchecked" })
private BindResult unmarshal(XMLEventReader staxEventReader, final Origin origin) {
XMLEvent event;
XMLEvent rootElementStartEvent;
try {
event = staxEventReader.peek();
while ( event != null && !event.isStartElement() ) {
rootElementStartEvent = staxEventReader.peek();
while ( rootElementStartEvent != null && !rootElementStartEvent.isStartElement() ) {
staxEventReader.nextEvent();
event = staxEventReader.peek();
rootElementStartEvent = staxEventReader.peek();
}
}
catch ( Exception e ) {
throw new MappingException( "Error accessing stax stream", e, origin );
}
if ( event == null ) {
if ( rootElementStartEvent == null ) {
throw new MappingException( "Could not locate root element", origin );
}
final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();
try {
final Schema schema = getSchema( event, origin );
staxEventReader = wrapReader( staxEventReader, event );
final Schema schema = getSchema( rootElementStartEvent, origin );
staxEventReader = wrapReader( staxEventReader, rootElementStartEvent );
final JAXBContext jaxbContext = getJaxbContext( event );
final JAXBContext jaxbContext = getJaxbContext( rootElementStartEvent );
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setSchema( schema );
unmarshaller.setEventHandler( handler );

View File

@ -0,0 +1,159 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.xml.internal.jaxb;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import javax.xml.validation.Schema;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.xml.internal.stax.BufferedXMLEventReader;
import org.hibernate.xml.internal.stax.LocalXmlResourceResolver;
import org.hibernate.xml.spi.BindResult;
import org.hibernate.xml.spi.Origin;
import org.hibernate.xml.spi.XmlBinder;
/**
* @author Steve Ebersole
*/
public abstract class AbstractXmlBinder2 implements XmlBinder {
private final boolean validateXml;
protected AbstractXmlBinder2() {
this( true );
}
protected AbstractXmlBinder2(boolean validateXml) {
this.validateXml = validateXml;
}
public boolean isValidationEnabled() {
return validateXml;
}
@Override
public BindResult bind(InputStream stream, Origin origin) {
final XMLEventReader eventReader = createReader( stream, origin );
try {
final StartElement rootElementStartEvent = seekRootElementStartEvent( eventReader, origin );
return doBind( eventReader, rootElementStartEvent, origin );
}
finally {
try {
eventReader.close();
}
catch ( Exception ignore ) {
}
}
}
protected XMLEventReader createReader(InputStream stream, Origin origin) {
try {
// create a standard StAX reader
final XMLEventReader staxReader = staxFactory().createXMLEventReader( stream );
// and wrap it in a buffered reader (keeping 100 element sized buffer)
return new BufferedXMLEventReader( staxReader, 100 );
}
catch ( XMLStreamException e ) {
throw new MappingException( "Unable to create stax reader", e, origin );
}
}
private XMLInputFactory staxFactory;
private XMLInputFactory staxFactory() {
if ( staxFactory == null ) {
staxFactory = buildStaxFactory();
}
return staxFactory;
}
@SuppressWarnings( { "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
XMLInputFactory staxFactory = XMLInputFactory.newInstance();
staxFactory.setXMLResolver( LocalXmlResourceResolver.INSTANCE );
return staxFactory;
}
protected StartElement seekRootElementStartEvent(XMLEventReader staxEventReader, Origin origin) {
XMLEvent rootElementStartEvent;
try {
rootElementStartEvent = staxEventReader.peek();
while ( rootElementStartEvent != null && !rootElementStartEvent.isStartElement() ) {
staxEventReader.nextEvent();
rootElementStartEvent = staxEventReader.peek();
}
}
catch ( Exception e ) {
throw new MappingException( "Error accessing stax stream", e, origin );
}
if ( rootElementStartEvent == null ) {
throw new MappingException( "Could not locate root element", origin );
}
return rootElementStartEvent.asStartElement();
}
protected abstract BindResult doBind(XMLEventReader staxEventReader, StartElement rootElementStartEvent, Origin origin);
protected static boolean hasNamespace(StartElement startElement) {
return ! "".equals( startElement.getName().getNamespaceURI() );
}
@SuppressWarnings("unchecked")
protected <T> T jaxb(XMLEventReader reader, Schema xsd, Class<T> modelClass, Origin origin) {
final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();
try {
final JAXBContext jaxbContext = JAXBContext.newInstance( modelClass );
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
if ( isValidationEnabled() ) {
unmarshaller.setSchema( xsd );
}
else {
unmarshaller.setSchema( null );
}
unmarshaller.setEventHandler( handler );
return (T) unmarshaller.unmarshal( reader );
}
catch ( JAXBException e ) {
throw new MappingException(
"Unable to perform unmarshalling at line number " + handler.getLineNumber()
+ " and column " + handler.getColumnNumber()
+ ". Message: " + handler.getMessage(),
e,
origin
);
}
}
}

View File

@ -128,7 +128,7 @@ public class MappingXmlBinder extends AbstractXmlBinder {
@SuppressWarnings( { "unchecked" })
public BindResult unmarshal(Document document, Origin origin) {
public BindResult bind(Document document, Origin origin) {
Element rootElement = document.getDocumentElement();
if ( rootElement == null ) {
throw new MappingException( "No root element found", origin );

View File

@ -0,0 +1,91 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.xml.internal.jaxb;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.StartElement;
import javax.xml.validation.Schema;
import org.hibernate.jaxb.spi.hbm.JaxbHibernateMapping;
import org.hibernate.metamodel.internal.source.hbm.transform.HbmXmlTransformer;
import org.hibernate.metamodel.spi.source.jaxb.JaxbEntityMappings;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.xml.internal.stax.LocalSchemaLocator;
import org.hibernate.xml.spi.BindResult;
import org.hibernate.xml.spi.Origin;
import org.jboss.logging.Logger;
/**
* Binder for the unified orm.xml schema
*
* @author Steve Ebersole
*/
public class UnifiedMappingBinder extends AbstractXmlBinder2 {
private static final Logger log = Logger.getLogger( MappingXmlBinder.class );
private static final Schema XSD = LocalSchemaLocator.resolveLocalSchema( "org/hibernate/xsd/mapping/orm-2.1.0.xsd" );
private static final Schema HBM_XSD =LocalSchemaLocator.resolveLocalSchema( "org/hibernate/hibernate-mapping-4.0.xsd" );
public static final String HBM_URI = "http://www.hibernate.org/xsd/hibernate-mapping";
public UnifiedMappingBinder() {
super();
}
public UnifiedMappingBinder(boolean validateXml) {
super( validateXml );
}
@Override
protected BindResult<JaxbEntityMappings> doBind(
XMLEventReader staxEventReader,
StartElement rootElementStartEvent,
Origin origin) {
final String rootElementLocalName = rootElementStartEvent.getName().getLocalPart();
if ( "hibernate-mappings".equals( rootElementLocalName ) ) {
// todo: finalize message test here, and possibly use a message logger
log.debug(
"Found legacy Hibernate hbm.xml mapping; performing on-the-fly transformation. " +
"Consider using build-time transformation tool to speed up run-time parsing"
);
XMLEventReader hbmReader = staxEventReader;
if ( !hasNamespace( rootElementStartEvent ) ) {
// if the elements are not namespaced in the source document, which can cause problems with validation
// and/or JAXB binding (since the xsd is namespaced). So we wrap the reader in a version that will
// return events that are namespaced versions of the original
hbmReader = new NamespaceAddingEventReader( staxEventReader, HBM_URI );
}
JaxbHibernateMapping hbmBindings = jaxb( hbmReader, HBM_XSD, JaxbHibernateMapping.class, origin );
return new BindResult<JaxbEntityMappings>( HbmXmlTransformer.INSTANCE.transform( hbmBindings ), origin );
}
else {
final XMLEventReader reader = new UnifiedMappingEventReader( staxEventReader );
final JaxbEntityMappings bindings = jaxb( reader, XSD, JaxbEntityMappings.class, origin );
return new BindResult<JaxbEntityMappings>( bindings, origin );
}
}
}

View File

@ -0,0 +1,142 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, 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.xml.internal.jaxb;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.EventReaderDelegate;
import org.jboss.logging.Logger;
/**
* @author Steve Ebersole
*/
public class UnifiedMappingEventReader extends EventReaderDelegate {
private static final Logger log = Logger.getLogger( UnifiedMappingEventReader.class );
public static final String NAMESPACE = "http://www.hibernate.org/xsd/orm";
public static final String VERSION = "2.1.0";
private static final List<String> JPA_NAMESPACE_URIS = Arrays.asList(
// JPA 1.0 and 2.0 namespace uri
"http://java.sun.com/xml/ns/persistence/orm",
// JPA 2.1 namespace uri
"http://xmlns.jcp.org/xml/ns/persistence/orm"
);
private final XMLEventFactory xmlEventFactory;
public UnifiedMappingEventReader(XMLEventReader reader) {
this( reader, XMLEventFactory.newInstance() );
}
public UnifiedMappingEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory) {
super( reader );
this.xmlEventFactory = xmlEventFactory;
}
@Override
public XMLEvent peek() throws XMLStreamException {
return wrap( super.peek() );
}
@Override
public XMLEvent nextEvent() throws XMLStreamException {
return wrap( super.nextEvent() );
}
private XMLEvent wrap(XMLEvent event) {
if ( event != null && event.isStartElement() ) {
return applyNamespace( event.asStartElement() );
}
return event;
}
@SuppressWarnings("unchecked")
private StartElement applyNamespace(StartElement startElement) {
Iterator<?> attributesItr;
Iterator<?> namespacesItr;
if ( "entity-mappings".equals( startElement.getName().getLocalPart() ) ) {
final List<Attribute> targetAttributeList = new ArrayList<Attribute>();
final List<Namespace> targetNamespaces = new ArrayList<Namespace>();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// attributes are pretty straight-forward; copy over any attributes
// *except* the version attribute and then add our specific unified
// schema version explicitly
final Iterator<Attribute> originalAttributes = startElement.getAttributes();
while ( originalAttributes.hasNext() ) {
final Attribute attribute = originalAttributes.next();
if ( !"version".equals( attribute.getName().getLocalPart() ) ) {
targetAttributeList.add( attribute );
}
}
targetAttributeList.add( xmlEventFactory.createAttribute( "version", VERSION ) );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// namespaces are a little more complicated. First we add our
// unified schema namespace as the default (no-prefix) namespace.
// Then we will check each of the original namespaces and if they
// have a uri matching any of the JPA mapping schema namespaces
// we will swap our uri; if the uri does not match, we will copy
// it as-is
final Iterator<Namespace> originalNamespaces = startElement.getNamespaces();
while ( originalNamespaces.hasNext() ) {
Namespace namespace = originalNamespaces.next();
if ( JPA_NAMESPACE_URIS.contains( namespace.getNamespaceURI() ) ) {
namespace = xmlEventFactory.createNamespace( namespace.getPrefix(), NAMESPACE );
}
targetNamespaces.add( namespace );
}
attributesItr = targetAttributeList.iterator();
namespacesItr = targetNamespaces.iterator();
}
else {
attributesItr = startElement.getAttributes();
namespacesItr = startElement.getNamespaces();
}
final StartElement adjusted = xmlEventFactory.createStartElement(
new QName( NAMESPACE, startElement.getName().getLocalPart() ),
attributesItr,
namespacesItr
);
if ( log.isDebugEnabled() ) {
log.debugf( "Created new StartElement with adjusted namespacing : %s ", adjusted );
}
return adjusted;
}
}

View File

@ -34,6 +34,10 @@ import javax.xml.validation.SchemaFactory;
import org.jboss.logging.Logger;
/**
* Helper for resolving XML Schema references locally.
* <p/>
* Note that *by design* we always use our ClassLoader to perform the lookups here.
*
* @author Steve Ebersole
*/
public class LocalSchemaLocator {

View File

@ -35,6 +35,7 @@ public 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" ),
ORM_2_1_0( "org/hibernate/xsd/mapping/orm-2.1.0.xsd" ),
HBM_4_0( "org/hibernate/hibernate-mapping-4.0.xsd" );
private final String schemaResourceName;
@ -53,6 +54,9 @@ public enum SupportedOrmXsdVersion {
else if ( "2.1".equals( name ) ) {
return ORM_2_1;
}
else if ( "2.1.0".equals( name ) ) {
return ORM_2_1_0;
}
else if ( "4.0".equals( name ) ) {
return HBM_4_0;
}

View File

@ -0,0 +1,115 @@
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ Copyright (c) 2014, 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
-->
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/hibernate-mapping">
<entity-mappings xmlns="http://www.hibernate.org/xsd/orm" version="2.1.0">
<description>
Hibernate orm.xml document auto-generated from legacy hbm.xml format via Hibernate-supplied
XSLT transformation (generated at <xsl:value-of select="current-dateTime()" />).
</description>
<persistence-unit-metadata>
<description>
Defines information which applies to the persistence unit overall, not just to this mapping file.
The XSLT transformation does not specify any persistence-unit-metadata itself.
</description>
<!-- By definition, the legacy hbm.xml files were utterly metadata complete -->
<xml-mapping-metadata-complete/>
<persistence-unit-defaults>
<description>
Defines defaults across the persistence unit overall, not just to this mapping file.
Again, the XSLT transformation does not specify any.
</description>
</persistence-unit-defaults>
</persistence-unit-metadata>
<xsl:if test="@package != ''">
<xsl:element name="default-package">
<xsl:value-of select="@package"/>
</xsl:element>
<xsl:element name="package">
<xsl:value-of select="@package"/>
</xsl:element>
</xsl:if>
<xsl:if test="@schema != ''">
<xsl:element name="schema">
<xsl:value-of select="@schema"/>
</xsl:element>
</xsl:if>
<xsl:if test="@catalog != ''">
<xsl:element name="catalog">
<xsl:value-of select="@catalog"/>
</xsl:element>
</xsl:if>
<xsl:if test="@default-access != ''">
<xsl:choose>
<xsl:when test="@default-acces = lower-case('property')">
<xsl:element name="access">
<xsl:text>PROPERTY</xsl:text>
</xsl:element>
</xsl:when>
<xsl:when test="@default-acces = lower-case('field')">
<xsl:element name="access">
<xsl:text>FIELD</xsl:text>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="custom-access">
<xsl:value-of select="@default-access"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="@auto-import != ''">
<xsl:element name="auto-import">
<xsl:value-of select="@auto-import"/>
</xsl:element>
</xsl:if>
<xsl:if test="@default-cascade != ''">
<xsl:element name="default-cascade">
<xsl:value-of select="@default-cascade"/>
</xsl:element>
</xsl:if>
<xsl:if test="@default-cascade != ''">
<xsl:element name="default-cascade">
<xsl:value-of select="@default-cascade"/>
</xsl:element>
</xsl:if>
</entity-mappings>
</xsl:template>
</xsl:transform>

View File

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
extensionBindingPrefixes="inheritance"
version="2.1">
<bindings schemaLocation="../resources/org/hibernate/xsd/mapping/orm-2.1.0.xsd" node="/xsd:schema">
<schemaBindings>
<package name="org.hibernate.metamodel.spi.source.jaxb" />
<nameXmlTransform>
<typeName prefix="Jaxb" />
<elementName prefix="Jaxb" />
<modelGroupName prefix="Jaxb" />
<anonymousTypeName prefix="Jaxb" />
</nameXmlTransform>
</schemaBindings>
<bindings node="//xsd:element[@name='entity-mappings']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='any']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='basic']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='element-collection']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='embedded']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='entity']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='id']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='many-to-any']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='many-to-one']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='version']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='hbm-tooling-hint']//xsd:attribute[@name='attribute']">
<property name="name"/>
</bindings>
<bindings node="//xsd:complexType[@name='hbm-tooling-hint']//xsd:attribute[@name='inherit']">
<property name="inheritable"/>
</bindings>
<bindings node="//xsd:complexType[@name='hbm-type-def']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.Parameterized</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='secondary-table']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.SchemaAware</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='table']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.SchemaAware</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='join-table']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.SchemaAware</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='collection-table']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.SchemaAware</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='table-generator']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.SchemaAware</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='sequence-generator']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.SchemaAware</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='entity']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ManagedType</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='embeddable']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ManagedType</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='mapped-superclass']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.ManagedType</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='id']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='version']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='basic']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='many-to-one']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='one-to-many']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='one-to-one']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='embedded-id']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='embedded']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='many-to-many']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='element-collection']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='any']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='many-to-any']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='pre-persist']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='pre-remove']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='pre-update']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='post-load']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='post-remove']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='post-update']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='post-persist']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='attributes']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.AttributesContainer</inheritance:implements>
</bindings>
<bindings node="//xsd:complexType[@name='embeddable-attributes']">
<inheritance:implements>org.hibernate.metamodel.spi.source.jaxb.AttributesContainer</inheritance:implements>
</bindings>
<!-- See http://stackoverflow.com/questions/4394134/jaxb-property-value-is-already-defined-use-jaxbproperty-to-resolve-this -->
<bindings node="//xsd:complexType[@name='any-discriminator-value-mapping']">
<bindings node=".//xsd:attribute[@name='value']">
<property name="DiscriminatorValue"/>
</bindings>
</bindings>
</bindings>
<!-- All bindings need to be serializable for cached metadata sources. -->
<globalBindings>
<serializable />
</globalBindings>
</bindings>

View File

@ -70,17 +70,15 @@ public abstract class AbstractMockerTest {
}
protected EntityMappingsMocker getEntityMappingsMocker(String... mappingFiles) {
MappingXmlBinder processor = new MappingXmlBinder( getServiceRegistry() );
ClassLoaderService classLoaderService = getServiceRegistry().getService( ClassLoaderService.class );
List<JaxbEntityMappings> xmlEntityMappingsList = new ArrayList<JaxbEntityMappings>();
for ( String fileName : mappingFiles ) {
MappingXmlBinder processor = new MappingXmlBinder( getServiceRegistry() );
BindResult bindResult = processor.bind(
classLoaderService.locateResourceStream( packagePrefix + fileName ),
new Origin( SourceType.FILE, packagePrefix + fileName )
);
JaxbEntityMappings entityMappings = (JaxbEntityMappings) bindResult.getRoot();
xmlEntityMappingsList.add( entityMappings );
}
return new EntityMappingsMocker( xmlEntityMappingsList, getIndex(), getServiceRegistry() );