Package org.hibernate

Examples of org.hibernate.AnnotationException


          throw new MappingException( "Unable to find entity: " + value.getReferencedEntityName() );
        }
        otherSideProperty = BinderHelper.findPropertyByName( otherSide, mappedBy );
      }
      catch (MappingException e) {
        throw new AnnotationException(
            "Unknown mappedBy in: " + StringHelper.qualify( ownerEntity, ownerProperty )
                + ", referenced property unknown: "
                + StringHelper.qualify( value.getReferencedEntityName(), mappedBy )
        );
      }
      if ( otherSideProperty == null ) {
        throw new AnnotationException(
            "Unknown mappedBy in: " + StringHelper.qualify( ownerEntity, ownerProperty )
                + ", referenced property unknown: "
                + StringHelper.qualify( value.getReferencedEntityName(), mappedBy )
        );
      }
      if ( otherSideProperty.getValue() instanceof OneToOne ) {
        propertyHolder.addProperty( prop, inferredData.getDeclaringClass() );
      }
      else if ( otherSideProperty.getValue() instanceof ManyToOne ) {
        Iterator it = otherSide.getJoinIterator();
        Join otherSideJoin = null;
        while ( it.hasNext() ) {
          Join otherSideJoinValue = (Join) it.next();
          if ( otherSideJoinValue.containsProperty( otherSideProperty ) ) {
            otherSideJoin = otherSideJoinValue;
            break;
          }
        }
        if ( otherSideJoin != null ) {
          //@OneToOne @JoinTable
          Join mappedByJoin = buildJoinFromMappedBySide(
              (PersistentClass) persistentClasses.get( ownerEntity ), otherSideProperty, otherSideJoin
          );
          ManyToOne manyToOne = new ManyToOne( mappings, mappedByJoin.getTable() );
          //FIXME use ignore not found here
          manyToOne.setIgnoreNotFound( ignoreNotFound );
          manyToOne.setCascadeDeleteEnabled( value.isCascadeDeleteEnabled() );
          manyToOne.setEmbedded( value.isEmbedded() );
          manyToOne.setFetchMode( value.getFetchMode() );
          manyToOne.setLazy( value.isLazy() );
          manyToOne.setReferencedEntityName( value.getReferencedEntityName() );
          manyToOne.setUnwrapProxy( value.isUnwrapProxy() );
          prop.setValue( manyToOne );
          Iterator otherSideJoinKeyColumns = otherSideJoin.getKey().getColumnIterator();
          while ( otherSideJoinKeyColumns.hasNext() ) {
            Column column = (Column) otherSideJoinKeyColumns.next();
            Column copy = new Column();
            copy.setLength( column.getLength() );
            copy.setScale( column.getScale() );
            copy.setValue( manyToOne );
            copy.setName( column.getQuotedName() );
            copy.setNullable( column.isNullable() );
            copy.setPrecision( column.getPrecision() );
            copy.setUnique( column.isUnique() );
            copy.setSqlType( column.getSqlType() );
            copy.setCheckConstraint( column.getCheckConstraint() );
            copy.setComment( column.getComment() );
            copy.setDefaultValue( column.getDefaultValue() );
            manyToOne.addColumn( copy );
          }
          mappedByJoin.addProperty( prop );
        }
        else {
          propertyHolder.addProperty( prop, inferredData.getDeclaringClass() );
        }

        value.setReferencedPropertyName( mappedBy );

        String propertyRef = value.getReferencedPropertyName();
        if ( propertyRef != null ) {
          mappings.addUniquePropertyReference(
              value.getReferencedEntityName(),
              propertyRef
          );
        }
      }
      else {
        throw new AnnotationException(
            "Referenced property not a (One|Many)ToOne: "
                + StringHelper.qualify(
                otherSide.getEntityName(), mappedBy
            )
                + " in mappedBy of "
View Full Code Here


      this.mappingColumn.setNullable( nullable );
      this.mappingColumn.setSqlType( sqlType );
      this.mappingColumn.setUnique( unique );
     
      if(writeExpression != null && !writeExpression.matches("[^?]*\\?[^?]*")) {
        throw new AnnotationException(
            "@WriteExpression must contain exactly one value placeholder ('?') character: property ["
                + propertyName + "] and column [" + logicalColumnName + "]"
        );
      }
      if ( readExpression != null) {
View Full Code Here

  }

  public Join getJoin() {
    Join join = joins.get( secondaryTableName );
    if ( join == null ) {
      throw new AnnotationException(
          "Cannot find the expected secondary table: no "
              + secondaryTableName + " available for " + propertyHolder.getClassName()
      );
    }
    else {
View Full Code Here

          StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() )
      );
      if ( overriddenCols != null ) {
        //check for overridden first
        if ( anns != null && overriddenCols.length != anns.length ) {
          throw new AnnotationException( "AttributeOverride.column() should override all columns for now" );
        }
        actualCols = overriddenCols.length == 0 ? null : overriddenCols;
        log.debug( "Column(s) overridden for property {}", inferredData.getPropertyName() );
      }
      if ( actualCols == null ) {
View Full Code Here

        if (columns[currentIndex].isFormula() || columns[currentIndex - 1].isFormula()) {
          continue;
        }
       
        if ( columns[currentIndex].isInsertable() != columns[currentIndex - 1].isInsertable() ) {
          throw new AnnotationException(
              "Mixing insertable and non insertable columns in a property is not allowed: " + propertyName
          );
        }
        if ( columns[currentIndex].isNullable() != columns[currentIndex - 1].isNullable() ) {
          throw new AnnotationException(
              "Mixing nullable and non nullable columns in a property is not allowed: " + propertyName
          );
        }
        if ( columns[currentIndex].isUpdatable() != columns[currentIndex - 1].isUpdatable() ) {
          throw new AnnotationException(
              "Mixing updatable and non updatable columns in a property is not allowed: " + propertyName
          );
        }
        if ( !columns[currentIndex].getTable().equals( columns[currentIndex - 1].getTable() ) ) {
          throw new AnnotationException(
              "Mixing different tables in a property is not allowed: " + propertyName
          );
        }
      }
    }
View Full Code Here

      if ( forColumn != null && !forColumn.equals( getName() ) ) {
        continue;
      }

      if ( alreadyProcessedForColumn ) {
        throw new AnnotationException( "Multiple definition of read/write conditions for column " + getName() );
      }

      readWrite[0] = annotationInstance.value( "read" ) == null ?
          null : annotationInstance.value( "read" ).asString();
      readWrite[1] = annotationInstance.value( "write" ) == null ?
View Full Code Here

    if ( !embeddedIdAnnotations.isEmpty() ) {
      if ( embeddedIdAnnotations.size() == 1 ) {
        return IdType.EMBEDDED;
      }
      else {
        throw new AnnotationException( "Multiple @EmbeddedId annotations are not allowed" );
      }
    }

    if ( !idAnnotations.isEmpty() ) {
      return idAnnotations.size() == 1 ? IdType.SIMPLE : IdType.COMPOSED;
View Full Code Here

        case INTEGER: {
          type = Integer.class;
          break;
        }
        default: {
          throw new AnnotationException( "Unsupported discriminator type: " + discriminatorType );
        }
      }

      discriminatorColumnValues.setName(
          JandexHelper.getValue(
View Full Code Here

  @Override
  public String resolveHibernateTypeName(AnnotationInstance enumeratedAnnotation) {
    boolean isEnum = mappedAttribute.getAttributeType().isEnum();
    if ( !isEnum ) {
      if ( enumeratedAnnotation != null ) {
        throw new AnnotationException( "Attribute " + mappedAttribute.getName() + " is not a Enumerated type, but has a @Enumerated annotation." );
      }
      else {
        return null;
      }
    }
View Full Code Here

  public String resolveHibernateTypeName(AnnotationInstance temporalAnnotation) {

    if ( isTemporalType( mappedAttribute.getAttributeType() ) ) {
      if ( temporalAnnotation == null ) {
        //SPEC 11.1.47 The Temporal annotation must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar.
        throw new AnnotationException( "Attribute " + mappedAttribute.getName() + " is a Temporal type, but no @Temporal annotation found." );
      }
      TemporalType temporalType = JandexHelper.getEnumValue( temporalAnnotation, "value", TemporalType.class );
      boolean isDate = Date.class.isAssignableFrom( mappedAttribute.getAttributeType() );
      String type;
      switch ( temporalType ) {
        case DATE:
          type = isDate ? StandardBasicTypes.DATE.getName() : StandardBasicTypes.CALENDAR_DATE.getName();
          break;
        case TIME:
          type = StandardBasicTypes.TIME.getName();
          if ( !isDate ) {
            throw new NotYetImplementedException( "Calendar cannot persist TIME only" );
          }
          break;
        case TIMESTAMP:
          type = isDate ? StandardBasicTypes.TIMESTAMP.getName() : StandardBasicTypes.CALENDAR.getName();
          break;
        default:
          throw new AssertionFailure( "Unknown temporal type: " + temporalType );
      }
      return type;
    }
    else {
      if ( temporalAnnotation != null ) {
        throw new AnnotationException(
            "@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + mappedAttribute
                .getName()
        );
      }
    }
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.