Examples of ManyToOne


Examples of org.hibernate.mapping.ManyToOne

        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() );
View Full Code Here

Examples of org.hibernate.mapping.ManyToOne

      else {
        mapKeyType = property.getMapKey().getName();
      }
      PersistentClass collectionEntity = (PersistentClass) persistentClasses.get( mapKeyType );
      boolean isIndexOfEntities = collectionEntity != null;
      ManyToOne element = null;
      org.hibernate.mapping.Map mapValue = (org.hibernate.mapping.Map) this.collection;
      if ( isIndexOfEntities ) {
        element = new ManyToOne( mappings, mapValue.getCollectionTable() );
        mapValue.setIndex( element );
        element.setReferencedEntityName( mapKeyType );
        //element.setFetchMode( fetchMode );
        //element.setLazy( fetchMode != FetchMode.JOIN );
        //make the second join non lazy
        element.setFetchMode( FetchMode.JOIN );
        element.setLazy( false );
        //does not make sense for a map key element.setIgnoreNotFound( ignoreNotFound );
      }
      else {
        XClass keyXClass;
        AnnotatedClassType classType;
View Full Code Here

Examples of se.unlogic.standardutils.dao.annotations.ManyToOne

        } else if (field.isAnnotationPresent(ManyToOne.class)) {

          this.checkAutoGeneration(daoManaged);

          ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);

          List<Field> remoteClassFields = ReflectionUtils.getFields(field.getType());

          Field matchingRemoteField = null;

          if (remoteClassFields != null) {

            for (Field remoteField : remoteClassFields) {

              if (remoteField.isAnnotationPresent(DAOManaged.class) && remoteField.isAnnotationPresent(OneToMany.class)
                  && remoteField.getType() == List.class && ReflectionUtils.isGenericlyTyped(remoteField)
                  && ((Class<?>) ReflectionUtils.getGenericType(remoteField) == this.beanClass)) {

                matchingRemoteField = remoteField;

                break;
              }
            }
          }

          if (matchingRemoteField == null) {

            throw new RuntimeException("No corresponding @OneToMany annotated field found in  " + field.getType()
                + " matching @ManyToOne relation of field " + field.getName() + " in  " + beanClass + "!");
          }

          Field remoteKeyField = null;

          if (!StringUtils.isEmpty(manyToOne.remoteKeyField())) {

            remoteKeyField = ReflectionUtils.getField(field.getType(), manyToOne.remoteKeyField());

            //TODO Check if the remote key field is @DAOPopluate annotated
            if (remoteKeyField == null) {

              throw new RuntimeException("Unable to find @Key annotated field " + manyToOne.remoteKeyField() + " in " + field.getType() + " specified for @ManyToOne annotated field "
                  + field.getName() + " in " + beanClass);
            }

          } else {

            for (Field remoteField : remoteClassFields) {

              if (remoteField.isAnnotationPresent(DAOManaged.class) && remoteField.isAnnotationPresent(Key.class)) {

                if (remoteKeyField != null) {

                  throw new RuntimeException("Found multiple @Key annotated fields in " + field.getType() + ", therefore the remoteKeyField property needs to be specified for the @ManyToOne annotated field "
                      + field.getName() + " in " + beanClass);
                }

                remoteKeyField = remoteField;
              }
            }

            if (remoteKeyField == null) {

              throw new RuntimeException("Unable to find @Key annotated field in " + field.getType() + " while parsing @ManyToOne annotated field "
                  + field.getName() + " in " + beanClass);
            }
          }

          DefaultManyToOneRelation<T, ?, ?> relation = null;

          if (field.isAnnotationPresent(Key.class)) {

            relation = DefaultManyToOneRelation.getGenericInstance(beanClass, field.getType(), remoteKeyField.getType(), field, remoteKeyField, daoManaged, daoFactory);

            manyToOneRelationKeys.put(field, relation);

          } else {

            relation = DefaultManyToOneRelation.getGenericInstance(beanClass, field.getType(), remoteKeyField.getType(), field, remoteKeyField, daoManaged, daoFactory);

            this.manyToOneRelations.put(field, relation);
          }

          this.columnMap.put(field, relation);

          if (orderBy != null) {
            this.columnOrderMap.put(orderBy, relation);
          }

          if (manyToOne.autoAdd()) {
            this.autoAddRelations.add(field);
          }

          if (manyToOne.autoUpdate()) {
            this.autoUpdateRelations.add(field);
          }

          if (manyToOne.autoGet()) {
            this.autoGetRelations.add(field);
          }

        } else if (field.isAnnotationPresent(ManyToMany.class)) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.