Package org.hibernate

Examples of org.hibernate.AnnotationException


  private static void checkAnyMetaDefValidity(boolean mustHaveName, AnyMetaDef defAnn, XAnnotatedElement annotatedElement) {
    if ( mustHaveName && isEmptyAnnotationValue( defAnn.name() ) ) {
      String name = XClass.class.isAssignableFrom( annotatedElement.getClass() ) ?
          ( (XClass) annotatedElement ).getName() :
          ( (XPackage) annotatedElement ).getName();
      throw new AnnotationException( "@AnyMetaDef.name cannot be null on an entity or a package: " + name );
    }
  }
View Full Code Here


  @SuppressWarnings({ "unchecked" })
  public void doSecondPass(Map persistentClasses) throws MappingException {
    PersistentClass referencedPersistentClass = (PersistentClass) persistentClasses.get( referencedEntityName );
    // TODO better error names
    if ( referencedPersistentClass == null ) {
      throw new AnnotationException( "Unknown entity name: " + referencedEntityName );
    }
    if ( ! ( referencedPersistentClass.getIdentifier() instanceof Component ) ) {
      throw new AssertionFailure(
          "Unexpected identifier type on the referenced entity when mapping a @MapsId: "
              + referencedEntityName
      );
    }
    Component referencedComponent = (Component) referencedPersistentClass.getIdentifier();
    Iterator<Property> properties = referencedComponent.getPropertyIterator();


    //prepare column name structure
    boolean isExplicitReference = true;
    Map<String, Ejb3JoinColumn> columnByReferencedName = new HashMap<String, Ejb3JoinColumn>(joinColumns.length);
    for (Ejb3JoinColumn joinColumn : joinColumns) {
      final String referencedColumnName = joinColumn.getReferencedColumn();
      if ( referencedColumnName == null || BinderHelper.isEmptyAnnotationValue( referencedColumnName ) ) {
        break;
      }
      //JPA 2 requires referencedColumnNames to be case insensitive
      columnByReferencedName.put( referencedColumnName.toLowerCase(), joinColumn );
    }
    //try default column orientation
    int index = 0;
    if ( columnByReferencedName.isEmpty() ) {
      isExplicitReference = false;
      for (Ejb3JoinColumn joinColumn : joinColumns) {
        columnByReferencedName.put( "" + index, joinColumn );
        index++;
      }
      index = 0;
    }

    while ( properties.hasNext() ) {
      Property referencedProperty = properties.next();
      if ( referencedProperty.isComposite() ) {
        throw new AssertionFailure( "Unexpected nested component on the referenced entity when mapping a @MapsId: "
            + referencedEntityName);
      }
      else {
        Property property = new Property();
        property.setName( referencedProperty.getName() );
        property.setNodeName( referencedProperty.getNodeName() );
        //FIXME set optional?
        //property.setOptional( property.isOptional() );
        property.setPersistentClass( component.getOwner() );
        property.setPropertyAccessorName( referencedProperty.getPropertyAccessorName() );
        SimpleValue value = new SimpleValue( mappings, component.getTable() );
        property.setValue( value );
        final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue();
        value.setTypeName( referencedValue.getTypeName() );
        value.setTypeParameters( referencedValue.getTypeParameters() );
        final Iterator<Selectable> columns = referencedValue.getColumnIterator();

        if ( joinColumns[0].isNameDeferred() ) {
          joinColumns[0].copyReferencedStructureAndCreateDefaultJoinColumns(
            referencedPersistentClass,
            columns,
            value);
        }
        else {
          //FIXME take care of Formula
          while ( columns.hasNext() ) {
            final Selectable selectable = columns.next();
            if ( ! Column.class.isInstance( selectable ) ) {
              log.debug( "Encountered formula definition; skipping" );
              continue;
            }
            final Column column = (Column) selectable;
            final Ejb3JoinColumn joinColumn;
            String logicalColumnName = null;
            if ( isExplicitReference ) {
              final String columnName = column.getName();
              logicalColumnName = mappings.getLogicalColumnName( columnName, referencedPersistentClass.getTable() );
              //JPA 2 requires referencedColumnNames to be case insensitive
              joinColumn = columnByReferencedName.get( logicalColumnName.toLowerCase() );
            }
            else {
              joinColumn = columnByReferencedName.get( "" + index );
              index++;
            }
            if ( joinColumn == null && ! joinColumns[0].isNameDeferred() ) {
              throw new AnnotationException(
                  isExplicitReference ?
                      "Unable to find column reference in the @MapsId mapping: " + logicalColumnName :
                      "Implicit column reference in the @MapsId mapping fails, try to use explicit referenceColumnNames: " + referencedEntityName
              );
            }
View Full Code Here

      return classes;
    }

    public void addAnyMetaDef(AnyMetaDef defAnn) throws AnnotationException {
      if ( anyMetaDefs.containsKey( defAnn.name() ) ) {
        throw new AnnotationException( "Two @AnyMetaDef with the same name defined: " + defAnn.name() );
      }
      anyMetaDefs.put( defAnn.name(), defAnn );
    }
View Full Code Here

      for ( String className : classNames ) {
        try {
          metadataSourceQueue.add( reflectionManager.classForName( className, this.getClass() ) );
        }
        catch ( ClassNotFoundException e ) {
          throw new AnnotationException( "Unable to load class defined in XML: " + className, e );
        }
      }
    }
  }
View Full Code Here

      String dependentTable = quotedTableName(sp.getValue().getTable());
      if ( dependentTable.compareTo( startTable ) == 0 ) {
        StringBuilder sb = new StringBuilder(
            "Foreign key circularity dependency involving the following tables: "
        );
        throw new AnnotationException( sb.toString() );
      }
      buildRecursiveOrderedFkSecondPasses( orderedFkSecondPasses, isADependencyOf, startTable, dependentTable );
      if ( !orderedFkSecondPasses.contains( sp ) ) {
        orderedFkSecondPasses.add( 0, sp );
      }
View Full Code Here

      for ( Column column : unboundNoLogical ) {
        sb.append("'").append( column.getName() ).append( "', " );
      }
      sb.setLength( sb.length() - 2 );
      sb.append( " not found. Make sure that you use the correct column name which depends on the naming strategy in use (it may not be the same as the property name in the entity, especially for relational types)" );
      throw new AnnotationException( sb.toString() );
    }
  }
View Full Code Here

  public void doSecondPass(java.util.Map persistentClasses) throws MappingException {
    if ( value instanceof ManyToOne ) {
      ManyToOne manyToOne = (ManyToOne) value;
      PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() );
      if ( ref == null ) {
        throw new AnnotationException(
            "@OneToOne or @ManyToOne on "
                + StringHelper.qualify( entityClassName, path )
                + " references an unknown entity: "
                + manyToOne.getReferencedEntityName()
        );
View Full Code Here

          mappedBy, entityBinder.getSecondaryTables(),
          propertyHolder, inferredData.getPropertyName(), mappings
      );
    }
    else if ( joinColumns == null && property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {
      throw new AnnotationException( "@Any requires an explicit @JoinColumn(s): "
          + BinderHelper.getPath( propertyHolder, inferredData ) );
    }
    if ( columns == null && !property.isAnnotationPresent( ManyToMany.class ) ) {
      //useful for collection of embedded elements
      columns = Ejb3Column.buildColumnFromAnnotation(
View Full Code Here

      joinColumns = Ejb3JoinColumn.buildJoinColumns(
          joinTableAnn.inverseJoinColumns(), null, entityBinder.getSecondaryTables(),
          propertyHolder, inferredData.getPropertyName(), mappings
      );
      if ( StringHelper.isEmpty( joinTableAnn.name() ) ) {
        throw new AnnotationException(
            "JoinTable.name() on a @ToOne association has to be explicit: "
                + BinderHelper.getPath( propertyHolder, inferredData )
        );
      }
    }
View Full Code Here

      else if ( property.isAnnotationPresent( JoinColumns.class ) ) {
        JoinColumns ann = property.getAnnotation( JoinColumns.class );
        anns = ann.value();
        int length = anns.length;
        if ( length == 0 ) {
          throw new AnnotationException( "Cannot bind an empty @JoinColumns" );
        }
      }
      if ( anns != null ) {
        joinColumns = Ejb3JoinColumn.buildJoinColumns(
            anns, null, entityBinder.getSecondaryTables(),
View Full Code Here

TOP

Related Classes of org.hibernate.AnnotationException

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.