Package org.hibernate.metamodel.source

Examples of org.hibernate.metamodel.source.MappingException


    }
  }

  private void checkQueryName(String name) {
    if ( namedQueryMap.containsKey( name ) || namedNativeQueryMap.containsKey( name ) ) {
      throw new MappingException( "Duplicated query mapping " + name, null );
    }
  }
View Full Code Here


  private void put(XMLSqlResultSetMapping mapping) {
    if ( mapping != null ) {
      Object old = sqlResultSetMappingMap.put( mapping.getName(), mapping );
      if ( old != null ) {
        throw new MappingException( "Duplicated SQL result set mapping " +  mapping.getName(), null );
      }
    }
  }
View Full Code Here

    if ( generatedValueAnnotation != null ) {
      String name = JandexHelper.getValue( generatedValueAnnotation, "generator", String.class );
      if ( StringHelper.isNotEmpty( name ) ) {
        generator = getContext().getMetadataImplementor().getIdGenerator( name );
        if ( generator == null ) {
          throw new MappingException( String.format( "Unable to find named generator %s", name ), null );
        }
      }
      else {
        GenerationType genType = JandexHelper.getEnumValue(
            generatedValueAnnotation,
View Full Code Here

        catch ( Exception ignore ) {
        }
      }
    }
    catch ( XMLStreamException e ) {
      throw new MappingException( "Unable to create stax reader", e, origin );
    }
  }
View Full Code Here

        staxEventReader.nextEvent();
        event = staxEventReader.peek();
      }
    }
    catch ( Exception e ) {
      throw new MappingException( "Error accessing stax stream", e, origin );
    }

    if ( event == null ) {
      throw new MappingException( "Could not locate root element", origin );
    }

    final Schema validationSchema;
    final Class jaxbTarget;

    final String elementName = event.asStartElement().getName().getLocalPart();

    if ( "entity-mappings".equals( elementName ) ) {
      final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME );
      final String explicitVersion = attribute == null ? null : attribute.getValue();
      validationSchema = resolveSupportedOrmXsd( explicitVersion );
      jaxbTarget = XMLEntityMappings.class;
    }
    else {
      validationSchema = hbmSchema();
      jaxbTarget = XMLHibernateMapping.class;
    }

    final Object target;
    final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();
    try {
      JAXBContext jaxbContext = JAXBContext.newInstance( jaxbTarget );
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      unmarshaller.setSchema( validationSchema );
      unmarshaller.setEventHandler( handler );
      target = unmarshaller.unmarshal( staxEventReader );
    }

    catch ( JAXBException e ) {
      StringBuilder builder = new StringBuilder();
      builder.append( "Unable to perform unmarshalling at line number " );
      builder.append( handler.getLineNumber() );
      builder.append( " and column " );
      builder.append( handler.getColumnNumber() );
      builder.append( ". Message: " );
      builder.append( handler.getMessage() );
      throw new MappingException( builder.toString(), e, origin );
    }

    return new JaxbRoot( target, origin );
  }
View Full Code Here

  @SuppressWarnings( { "unchecked" })
  public JaxbRoot unmarshal(Document document, Origin origin) {
    Element rootElement = document.getDocumentElement();
    if ( rootElement == null ) {
      throw new MappingException( "No root element found", origin );
    }

    final Schema validationSchema;
    final Class jaxbTarget;

    if ( "entity-mappings".equals( rootElement.getNodeName() ) ) {
      final String explicitVersion = rootElement.getAttribute( "version" );
      validationSchema = resolveSupportedOrmXsd( explicitVersion );
      jaxbTarget = XMLEntityMappings.class;
    }
    else {
      validationSchema = hbmSchema();
      jaxbTarget = XMLHibernateMapping.class;
    }

    final Object target;
    try {
      JAXBContext jaxbContext = JAXBContext.newInstance( jaxbTarget );
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      unmarshaller.setSchema( validationSchema );
      target = unmarshaller.unmarshal( new DOMSource( document ) );
    }
    catch ( JAXBException e ) {
      throw new MappingException( "Unable to perform unmarshalling", e, origin );
    }

    return new JaxbRoot( target, origin );
  }
View Full Code Here

            LOG.tracef( "found mapping document : %s", zipEntry.getName() );
            try {
              add( jarFile.getInputStream( zipEntry ), origin, true );
            }
            catch ( Exception e ) {
              throw new MappingException( "could not read mapping documents", e, origin );
            }
          }
        }
      }
      finally {
View Full Code Here

        }
        catch (ClassLoadingException e) {
          throw e;
        }
        catch (Exception e) {
          throw new MappingException(
              "could not instantiate custom database object class [" + className + "]",
              jaxbRoot.getOrigin()
          );
        }
      }
View Full Code Here

              paramElement.getName(),
              metadata.getTypeResolver().heuristicType( paramElement.getType() )
          );
        }
        else {
          throw new MappingException( "Unrecognized nested filter content", jaxbRoot.getOrigin() );
        }
      }
      if ( condition == null ) {
        condition = filterDefinition.getCondition();
      }
View Full Code Here

      String profileName = fetchProfile.getName();
      Set<FetchProfile.Fetch> fetches = new HashSet<FetchProfile.Fetch>();
      for ( XMLFetchProfileElement.XMLFetch fetch : fetchProfile.getFetch() ) {
        String entityName = fetch.getEntity() == null ? containingEntityName : fetch.getEntity();
        if ( entityName == null ) {
          throw new MappingException(
              "could not determine entity for fetch-profile fetch [" + profileName + "]:[" +
                  fetch.getAssociation() + "]",
              jaxbRoot.getOrigin()
          );
        }
View Full Code Here

TOP

Related Classes of org.hibernate.metamodel.source.MappingException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.