Search in sources :

Example 21 with MappingException

use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.

the class AbstractBinder method seekRootElementStartEvent.

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();
}
Also used : XMLEvent(javax.xml.stream.events.XMLEvent) JAXBException(javax.xml.bind.JAXBException) XMLStreamException(javax.xml.stream.XMLStreamException) MappingException(org.hibernate.boot.MappingException) MappingException(org.hibernate.boot.MappingException)

Example 22 with MappingException

use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.

the class AbstractBinder method jaxb.

@SuppressWarnings("unchecked")
protected <T> T jaxb(XMLEventReader reader, Schema xsd, JAXBContext jaxbContext, Origin origin) {
    final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();
    try {
        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);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) Unmarshaller(javax.xml.bind.Unmarshaller) MappingException(org.hibernate.boot.MappingException)

Aggregations

MappingException (org.hibernate.boot.MappingException)22 Identifier (org.hibernate.boot.model.naming.Identifier)7 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)4 RelationalValueSource (org.hibernate.boot.model.source.spi.RelationalValueSource)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Property (org.hibernate.mapping.Property)3 HashSet (java.util.HashSet)2 List (java.util.List)2 JAXBException (javax.xml.bind.JAXBException)2 JaxbHbmNativeQueryPropertyReturnType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryPropertyReturnType)2 ColumnSource (org.hibernate.boot.model.source.spi.ColumnSource)2 DerivedValueSource (org.hibernate.boot.model.source.spi.DerivedValueSource)2 VersionAttributeSource (org.hibernate.boot.model.source.spi.VersionAttributeSource)2 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)2 FilterDefinition (org.hibernate.engine.spi.FilterDefinition)2 Component (org.hibernate.mapping.Component)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 SimpleValue (org.hibernate.mapping.SimpleValue)2 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)2