Package org.hibernate

Examples of org.hibernate.MappingException


  public Property getReferencedProperty(String propertyPath) throws MappingException {
    try {
      return getRecursiveProperty( propertyPath, getReferenceablePropertyIterator() );
    }
    catch ( MappingException e ) {
      throw new MappingException(
          "property-ref [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e
      );
    }
  }
View Full Code Here


  public Property getRecursiveProperty(String propertyPath) throws MappingException {
    try {
      return getRecursiveProperty( propertyPath, getPropertyIterator() );
    }
    catch ( MappingException e ) {
      throw new MappingException(
          "property [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e
      );
    }
  }
View Full Code Here

          property = ( ( Component ) property.getValue() ).getProperty( element );
        }
      }
    }
    catch ( MappingException e ) {
      throw new MappingException( "property [" + propertyPath + "] not found on entity [" + getEntityName() + "]" );
    }

    return property;
  }
View Full Code Here

      Property prop = (Property) iterator.next();
      if ( prop.getName().equals( StringHelper.root(propertyName) ) ) {
        return prop;
      }
    }
    throw new MappingException( "property [" + propertyName + "] not found on entity [" + getEntityName() + "]" );
  }
View Full Code Here

  public void validate(Mapping mapping) throws MappingException {
    Iterator iter = getPropertyIterator();
    while ( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      if ( !prop.isValid(mapping) ) {
        throw new MappingException(
            "property mapping has wrong number of columns: " +
            StringHelper.qualify( getEntityName(), prop.getName() ) +
            " type: " +
            prop.getType().getName()
          );
View Full Code Here

    HashSet names = new HashSet();
    Iterator iter = getPropertyIterator();
    while ( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      if ( !names.add( prop.getName() ) ) {
        throw new MappingException( "Duplicate property mapping of " + prop.getName() + " found in " + getEntityName());
      }
    }
  }
View Full Code Here

    while ( columns.hasNext() ) {
      Selectable columnOrFormula = (Selectable) columns.next();
      if ( !columnOrFormula.isFormula() ) {
        Column col = (Column) columnOrFormula;
        if ( !distinctColumns.add( col.getName() ) ) {
          throw new MappingException(
              "Repeated column in mapping for entity: " +
              getEntityName() +
              " column: " +
              col.getName() +
              " (should be mapped with insert=\"false\" update=\"false\")"
View Full Code Here

    final Object discriminatorValue;
    if ( persistentClass.isPolymorphic() ) {
      Value discrimValue = persistentClass.getDiscriminator();
      if (discrimValue==null) {
        throw new MappingException("discriminator mapping required for single table polymorphic persistence");
      }
      forceDiscriminator = persistentClass.isForceDiscriminator();
      Selectable selectable = (Selectable) discrimValue.getColumnIterator().next();
      if ( discrimValue.hasFormula() ) {
        Formula formula = (Formula) selectable;
        discriminatorFormula = formula.getFormula();
        discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        discriminatorColumnName = null;
        discriminatorAlias = "clazz_";
      }
      else {
        Column column = (Column) selectable;
        discriminatorColumnName = column.getQuotedName( factory.getDialect() );
        discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
        discriminatorFormula = null;
        discriminatorFormulaTemplate = null;
      }
      discriminatorType = persistentClass.getDiscriminator().getType();
      if ( persistentClass.isDiscriminatorValueNull() ) {
        discriminatorValue = NULL_DISCRIMINATOR;
        discriminatorSQLValue = InFragment.NULL;
        discriminatorInsertable = false;
      }
      else if ( persistentClass.isDiscriminatorValueNotNull() ) {
        discriminatorValue = NOT_NULL_DISCRIMINATOR;
        discriminatorSQLValue = InFragment.NOT_NULL;
        discriminatorInsertable = false;
      }
      else {
        discriminatorInsertable = persistentClass.isDiscriminatorInsertable() && !discrimValue.hasFormula();
        try {
          DiscriminatorType dtype = (DiscriminatorType) discriminatorType;
          discriminatorValue = dtype.stringToObject( persistentClass.getDiscriminatorValue() );
          discriminatorSQLValue = dtype.objectToSQLString( discriminatorValue, factory.getDialect() );
        }
        catch (ClassCastException cce) {
          throw new MappingException("Illegal discriminator type: " + discriminatorType.getName() );
        }
        catch (Exception e) {
          throw new MappingException("Could not format discriminator value to SQL string", e);
        }
      }
    }
    else {
      forceDiscriminator = false;
      discriminatorInsertable = false;
      discriminatorColumnName = null;
      discriminatorAlias = null;
      discriminatorType = null;
      discriminatorValue = null;
      discriminatorSQLValue = null;
      discriminatorFormula = null;
      discriminatorFormulaTemplate = null;
    }

    // PROPERTIES

    propertyTableNumbers = new int[ getPropertySpan() ];
    Iterator iter = persistentClass.getPropertyClosureIterator();
    int i=0;
    while( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      propertyTableNumbers[i++] = persistentClass.getJoinNumber(prop);

    }

    //TODO: code duplication with JoinedSubclassEntityPersister
   
    ArrayList columnJoinNumbers = new ArrayList();
    ArrayList formulaJoinedNumbers = new ArrayList();
    ArrayList propertyJoinNumbers = new ArrayList();
   
    iter = persistentClass.getSubclassPropertyClosureIterator();
    while ( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      Integer join = new Integer( persistentClass.getJoinNumber(prop) );
      propertyJoinNumbers.add(join);

      //propertyTableNumbersByName.put( prop.getName(), join );
      propertyTableNumbersByNameAndSubclass.put(
          prop.getPersistentClass().getEntityName() + '.' + prop.getName(),
          join
      );

      Iterator citer = prop.getColumnIterator();
      while ( citer.hasNext() ) {
        Selectable thing = (Selectable) citer.next();
        if ( thing.isFormula() ) {
          formulaJoinedNumbers.add(join);
        }
        else {
          columnJoinNumbers.add(join);
        }
      }
    }
    subclassColumnTableNumberClosure = ArrayHelper.toIntArray(columnJoinNumbers);
    subclassFormulaTableNumberClosure = ArrayHelper.toIntArray(formulaJoinedNumbers);
    subclassPropertyTableNumberClosure = ArrayHelper.toIntArray(propertyJoinNumbers);

    int subclassSpan = persistentClass.getSubclassSpan() + 1;
    subclassClosure = new String[subclassSpan];
    subclassClosure[0] = getEntityName();
    if ( persistentClass.isPolymorphic() ) {
      subclassesByDiscriminatorValue.put( discriminatorValue, getEntityName() );
    }

    // SUBCLASSES
    if ( persistentClass.isPolymorphic() ) {
      iter = persistentClass.getSubclassIterator();
      int k=1;
      while ( iter.hasNext() ) {
        Subclass sc = (Subclass) iter.next();
        subclassClosure[k++] = sc.getEntityName();
        if ( sc.isDiscriminatorValueNull() ) {
          subclassesByDiscriminatorValue.put( NULL_DISCRIMINATOR, sc.getEntityName() );
        }
        else if ( sc.isDiscriminatorValueNotNull() ) {
          subclassesByDiscriminatorValue.put( NOT_NULL_DISCRIMINATOR, sc.getEntityName() );
        }
        else {
          try {
            DiscriminatorType dtype = (DiscriminatorType) discriminatorType;
            subclassesByDiscriminatorValue.put(
              dtype.stringToObject( sc.getDiscriminatorValue() ),
              sc.getEntityName()
            );
          }
          catch (ClassCastException cce) {
            throw new MappingException("Illegal discriminator type: " + discriminatorType.getName() );
          }
          catch (Exception e) {
            throw new MappingException("Error parsing discriminator value", e);
          }
        }
      }
    }
View Full Code Here

        String typeFromXML = HbmBinder.getTypeFromXML( returnElem );
        Type type = null;
        if(typeFromXML!=null) {
          type = TypeFactory.heuristicType( typeFromXML );
          if ( type == null ) {
            throw new MappingException( "could not determine type " + type );
          }
        }
        definition.addQueryReturn( new NativeSQLQueryScalarReturn( column, type ) );
      }
      else if ( "return".equals( name ) ) {
View Full Code Here

      alias = "alias_" + elementCount; // hack/workaround as sqlquery impl depend on having a key.
    }

    String entityName = HbmBinder.getEntityName(returnElem, mappings);
    if(entityName==null) {
      throw new MappingException( "<return alias='" + alias + "'> must specify either a class or entity-name");
    }
    LockMode lockMode = getLockMode( returnElem.attributeValue( "lock-mode" ) );

    PersistentClass pc = mappings.getClass( entityName );
    java.util.Map propertyResults = bindPropertyResults(alias, returnElem, pc, mappings );
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.