Package org.hibernate

Examples of org.hibernate.MappingException


         * 1. get the parent property
         * 2. list all the properties following the expected one in the parent property
         * 3. calculate the lowest index and insert the property
         */
        if (pc == null)
          throw new MappingException("dotted notation in <return-join> or <load_collection> not yet supported");
        int dotIndex = name.lastIndexOf( '.' );
        String reducedName = name.substring( 0, dotIndex );
        Value value = pc.getRecursiveProperty( reducedName ).getValue();
        Iterator parentPropIter;
        if ( value instanceof Component ) {
          Component comp = (Component) value;
          parentPropIter = comp.getPropertyIterator();
        }
        else if ( value instanceof ToOne ) {
          ToOne toOne = (ToOne) value;
          PersistentClass referencedPc = mappings.getClass( toOne.getReferencedEntityName() );
          if ( toOne.getReferencedPropertyName() != null ) {
            try {
              parentPropIter = ( (Component) referencedPc.getRecursiveProperty( toOne.getReferencedPropertyName() ).getValue() ).getPropertyIterator();
            } catch (ClassCastException e) {
              throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
            }
          }
          else {
            try {
              if ( referencedPc.getIdentifierMapper() == null ) {
                parentPropIter = ( (Component) referencedPc.getIdentifierProperty().getValue() ).getPropertyIterator();
              }
              else {
                parentPropIter = referencedPc.getIdentifierMapper().getPropertyIterator();
              }
            }
            catch (ClassCastException e) {
              throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
            }
          }
        }
        else {
          throw new MappingException("dotted notation reference neither a component nor a many/one to one");
        }
        boolean hasFollowers = false;
        List followers = new ArrayList();
        while ( parentPropIter.hasNext() ) {
          String currentPropertyName = ( (Property) parentPropIter.next() ).getName();
          String currentName = reducedName + '.' + currentPropertyName;
          if (hasFollowers) {
            followers.add( currentName );
          }
          if ( name.equals( currentName ) ) hasFollowers = true;
        }

        int index = propertyNames.size();
        int followersSize = followers.size();
        for (int loop = 0 ; loop < followersSize ; loop++) {
          String follower = (String) followers.get(loop);
          int currentIndex = getIndexOfFirstMatchingProperty(propertyNames, follower);
          index = currentIndex != -1 && currentIndex < index ? currentIndex : index;
        }
        propertyNames.add(index, name);
        properties.add(index, propertyresult);
      }
    }

    Set uniqueReturnProperty = new HashSet();
    iterator = properties.iterator();
    while ( iterator.hasNext() ) {
      Element propertyresult = (Element) iterator.next();
      String name = propertyresult.attributeValue("name");
      if ( "class".equals(name) ) {
        throw new MappingException(
            "class is not a valid property name to use in a <return-property>, use <return-discriminator> instead"
          );
      }
      //TODO: validate existing of property with the chosen name. (secondpass )
      ArrayList allResultColumns = getResultColumns(propertyresult);

      if ( allResultColumns.isEmpty() ) {
        throw new MappingException(
            "return-property for alias " + alias +
            " must specify at least one column or return-column name"
          );
      }
      if ( uniqueReturnProperty.contains( name ) ) {
        throw new MappingException(
            "duplicate return-property for property " + name +
            " on alias " + alias
          );
      }
      uniqueReturnProperty.add(name);
View Full Code Here


    }
    else if ( "pessimistic_force_increment".equals( lockMode ) ) {
      return LockMode.PESSIMISTIC_FORCE_INCREMENT;
    }
    else {
      throw new MappingException( "unknown lockmode" );
    }
  }
View Full Code Here

    super( queryDef.getQueryString(), queryDef.getFlushMode(), session, parameterMetadata );
    this.session = session;
    if ( queryDef.getResultSetRef() != null ) {
      ResultSetMappingDefinition definition = session.getFactory().getResultSetMapping( queryDef.getResultSetRef() );
      if ( definition == null ) {
        throw new MappingException( "Unable to find resultset-ref definition: " + queryDef.getResultSetRef() );
      }
      this.queryReturns = new ArrayList<NativeSQLQueryReturn>( Arrays.asList( definition.getQueryReturns() ) );
    }
    else if ( queryDef.getQueryReturns() != null && queryDef.getQueryReturns().length > 0 ) {
      this.queryReturns = new ArrayList<NativeSQLQueryReturn>( Arrays.asList( queryDef.getQueryReturns() ) );
View Full Code Here

  @Override
  public SQLQuery setResultSetMapping(String name) {
    ResultSetMappingDefinition mapping = session.getFactory().getResultSetMapping( name );
    if ( mapping == null ) {
      throw new MappingException( "Unknown SqlResultSetMapping [" + name + "]" );
    }
    NativeSQLQueryReturn[] returns = mapping.getQueryReturns();
    queryReturns.addAll( Arrays.asList( returns ) );
    return this;
  }
View Full Code Here

  }

  private NamedSQLQueryDefinition findNamedNativeQuery(String queryName) {
    NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
    if ( nsqlqd == null ) {
      throw new MappingException( "Named native query not found: " + queryName );
    }
    return nsqlqd;
  }
View Full Code Here

       * Returns the identifier type of a mapped class
       */
      public Type getIdentifierType(String entityName) throws MappingException {
        PersistentClass pc = classes.get( entityName );
        if ( pc == null ) {
          throw new MappingException( "persistent class not known: " + entityName );
        }
        return pc.getIdentifier().getType();
      }

      public String getIdentifierPropertyName(String entityName) throws MappingException {
        final PersistentClass pc = classes.get( entityName );
        if ( pc == null ) {
          throw new MappingException( "persistent class not known: " + entityName );
        }
        if ( !pc.hasIdentifierProperty() ) {
          return null;
        }
        return pc.getIdentifierProperty().getName();
      }

      public Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
        final PersistentClass pc = classes.get( entityName );
        if ( pc == null ) {
          throw new MappingException( "persistent class not known: " + entityName );
        }
        Property prop = pc.getReferencedProperty( propertyName );
        if ( prop == null ) {
          throw new MappingException(
              "property not known: " +
              entityName + '.' + propertyName
            );
        }
        return prop.getType();
View Full Code Here

    while ( itr.hasNext() ) {
      Mappings.PropertyReference upr = (Mappings.PropertyReference) itr.next();

      PersistentClass clazz = getClassMapping( upr.referencedClass );
      if ( clazz == null ) {
        throw new MappingException(
            "property-ref to unmapped class: " +
            upr.referencedClass
          );
      }
View Full Code Here

        }
        if ( iterator.hasNext() ) {
          buf.append( "," );
        }
      }
      throw new MappingException( buf.toString() );
    }

    return added;
  }
View Full Code Here

      ForeignKey fk = (ForeignKey) iter.next();
      if ( !done.contains( fk ) ) {
        done.add( fk );
        final String referencedEntityName = fk.getReferencedEntityName();
        if ( referencedEntityName == null ) {
          throw new MappingException(
              "An association from the table " +
              fk.getTable().getName() +
              " does not specify the referenced entity"
            );
        }
                LOG.debugf("Resolving reference to class: %s", referencedEntityName);
        PersistentClass referencedClass = classes.get( referencedEntityName );
        if ( referencedClass == null ) {
          throw new MappingException(
              "An association from the table " +
              fk.getTable().getName() +
              " refers to an unmapped class: " +
              referencedEntityName
            );
View Full Code Here

    try {
      List errors = new ArrayList();
      Document document = xmlHelper.createSAXReader( resourceName, errors, entityResolver )
          .read( new InputSource( stream ) );
      if ( errors.size() != 0 ) {
        throw new MappingException( "invalid configuration", (Throwable) errors.get( 0 ) );
      }
      doConfigure( document );
    }
    catch (DocumentException e) {
      throw new HibernateException( "Could not parse configuration: " + resourceName, e );
View Full Code Here

TOP

Related Classes of org.hibernate.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.