Examples of ElementCollection


Examples of javax.persistence.ElementCollection

          || property.isAnnotationPresent( ManyToMany.class )
          || property.isAnnotationPresent( ElementCollection.class )
          || property.isAnnotationPresent( ManyToAny.class ) ) {
        OneToMany oneToManyAnn = property.getAnnotation( OneToMany.class );
        ManyToMany manyToManyAnn = property.getAnnotation( ManyToMany.class );
        ElementCollection elementCollectionAnn = property.getAnnotation( ElementCollection.class );

        final IndexColumn indexColumn;

        if ( property.isAnnotationPresent( OrderColumn.class ) ) {
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( OrderColumn.class ),
              propertyHolder,
              inferredData,
              entityBinder.getSecondaryTables(),
              mappings
          );
          if ( property.isAnnotationPresent( ListIndexBase.class ) ) {
            indexColumn.setBase( ( property.getAnnotation( ListIndexBase.class ) ).value() );
          }
        }
        else {
          //if @IndexColumn is not there, the generated IndexColumn is an implicit column and not used.
          //so we can leave the legacy processing as the default
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( org.hibernate.annotations.IndexColumn.class ),
              propertyHolder,
              inferredData,
              mappings
          );
        }
        CollectionBinder collectionBinder = CollectionBinder.getCollectionBinder(
            propertyHolder.getEntityName(),
            property,
            !indexColumn.isImplicit(),
            property.isAnnotationPresent( MapKeyType.class ),
            mappings
        );
        collectionBinder.setIndexColumn( indexColumn );
        collectionBinder.setMapKey( property.getAnnotation( MapKey.class ) );
        collectionBinder.setPropertyName( inferredData.getPropertyName() );

        collectionBinder.setBatchSize( property.getAnnotation( BatchSize.class ) );

        collectionBinder.setJpaOrderBy( property.getAnnotation( javax.persistence.OrderBy.class ) );
        collectionBinder.setSqlOrderBy( property.getAnnotation( OrderBy.class ) );

        collectionBinder.setSort( property.getAnnotation( Sort.class ) );
        collectionBinder.setNaturalSort( property.getAnnotation( SortNatural.class ) );
        collectionBinder.setComparatorSort( property.getAnnotation( SortComparator.class ) );

        Cache cachAnn = property.getAnnotation( Cache.class );
        collectionBinder.setCache( cachAnn );
        collectionBinder.setPropertyHolder( propertyHolder );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        collectionBinder.setIgnoreNotFound( ignoreNotFound );
        collectionBinder.setCollectionType( inferredData.getProperty().getElementClass() );
        collectionBinder.setMappings( mappings );
        collectionBinder.setAccessType( inferredData.getDefaultAccess() );

        Ejb3Column[] elementColumns;
        //do not use "element" if you are a JPA 2 @ElementCollection only for legacy Hibernate mappings
        boolean isJPA2ForValueMapping = property.isAnnotationPresent( ElementCollection.class );
        PropertyData virtualProperty = isJPA2ForValueMapping ? inferredData : new WrappedInferredData(
            inferredData, "element"
        );
        if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
            Formula.class
        ) ) {
          Column ann = property.getAnnotation( Column.class );
          Formula formulaAnn = property.getAnnotation( Formula.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              new Column[] { ann },
              formulaAnn,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else if ( property.isAnnotationPresent( Columns.class ) ) {
          Columns anns = property.getAnnotation( Columns.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              anns.columns(), null, nullability, propertyHolder, virtualProperty,
              entityBinder.getSecondaryTables(), mappings
          );
        }
        else {
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              null,
              null,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        {
          Column[] keyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
          }

          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          //nullify empty array
          keyColumns = keyColumns != null && keyColumns.length > 0 ? keyColumns : null;

          //"mapkey" is the legacy column name of the key column pre JPA 2
          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
              keyColumns,
              null,
              Nullability.FORCED_NOT_NULL,
              propertyHolder,
              isJPA2 ? inferredData : mapKeyVirtualProperty,
              isJPA2 ? "_KEY" : null,
              entityBinder.getSecondaryTables(),
              mappings
          );
          collectionBinder.setMapKeyColumns( mapColumns );
        }
        {
          JoinColumn[] joinKeyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyJoinColumns.class ) ) {
            isJPA2 = Boolean.TRUE;
            final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class )
                .value();
            joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
            int index = 0;
            for ( MapKeyJoinColumn joinColumn : mapKeyJoinColumns ) {
              joinKeyColumns[index] = new MapKeyJoinColumnDelegator( joinColumn );
              index++;
            }
            if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
              throw new AnnotationException(
                  "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
                      + BinderHelper.getPath( propertyHolder, inferredData )
              );
            }
          }
          else if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            joinKeyColumns = new JoinColumn[] {
                new MapKeyJoinColumnDelegator(
                    property.getAnnotation(
                        MapKeyJoinColumn.class
                    )
                )
            };
          }
          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3JoinColumn[] mapJoinColumns = Ejb3JoinColumn.buildJoinColumnsWithDefaultColumnSuffix(
              joinKeyColumns,
              null,
              entityBinder.getSecondaryTables(),
              propertyHolder,
              isJPA2 ? inferredData.getPropertyName() : mapKeyVirtualProperty.getPropertyName(),
              isJPA2 ? "_KEY" : null,
              mappings
          );
          collectionBinder.setMapKeyManyToManyColumns( mapJoinColumns );
        }

        //potential element
        collectionBinder.setEmbedded( property.isAnnotationPresent( Embedded.class ) );
        collectionBinder.setElementColumns( elementColumns );
        collectionBinder.setProperty( property );

        //TODO enhance exception with @ManyToAny and @CollectionOfElements
        if ( oneToManyAnn != null && manyToManyAnn != null ) {
          throw new AnnotationException(
              "@OneToMany and @ManyToMany on the same property is not allowed: "
                  + propertyHolder.getEntityName() + "." + inferredData.getPropertyName()
          );
        }
        String mappedBy = null;
        if ( oneToManyAnn != null ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = oneToManyAnn.mappedBy();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() )
          );
          collectionBinder.setCascadeStrategy(
              getCascadeStrategy(
                  oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
              )
          );
          collectionBinder.setOneToMany( true );
        }
        else if ( elementCollectionAnn != null ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = "";
          final Class<?> targetElement = elementCollectionAnn.targetClass();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( targetElement )
          );
          //collectionBinder.setCascadeStrategy( getCascadeStrategy( embeddedCollectionAnn.cascade(), hibernateCascade ) );
          collectionBinder.setOneToMany( true );
View Full Code Here

Examples of javax.persistence.ElementCollection

  private void defineFetchingStrategy() {
    LazyCollection lazy = property.getAnnotation( LazyCollection.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    OneToMany oneToMany = property.getAnnotation( OneToMany.class );
    ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
    ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2
    ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
    FetchType fetchType;
    if ( oneToMany != null ) {
      fetchType = oneToMany.fetch();
    }
    else if ( manyToMany != null ) {
      fetchType = manyToMany.fetch();
    }
    else if ( elementCollection != null ) {
      fetchType = elementCollection.fetch();
    }
    else if ( manyToAny != null ) {
      fetchType = FetchType.LAZY;
    }
    else {
View Full Code Here

Examples of javax.persistence.ElementCollection

          || property.isAnnotationPresent( ManyToMany.class )
          || property.isAnnotationPresent( ElementCollection.class )
          || property.isAnnotationPresent( ManyToAny.class ) ) {
        OneToMany oneToManyAnn = property.getAnnotation( OneToMany.class );
        ManyToMany manyToManyAnn = property.getAnnotation( ManyToMany.class );
        ElementCollection elementCollectionAnn = property.getAnnotation( ElementCollection.class );

        final IndexColumn indexColumn;

        if ( property.isAnnotationPresent( OrderColumn.class ) ) {
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( OrderColumn.class ),
              propertyHolder,
              inferredData,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else {
          //if @IndexColumn is not there, the generated IndexColumn is an implicit column and not used.
          //so we can leave the legacy processing as the default
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( org.hibernate.annotations.IndexColumn.class ),
              propertyHolder,
              inferredData,
              mappings
          );
        }
        CollectionBinder collectionBinder = CollectionBinder.getCollectionBinder(
            propertyHolder.getEntityName(),
            property,
            !indexColumn.isImplicit(),
            property.isAnnotationPresent( MapKeyType.class )

            // || property.isAnnotationPresent( ManyToAny.class )
        );
        collectionBinder.setIndexColumn( indexColumn );
        collectionBinder.setMapKey( property.getAnnotation( MapKey.class ) );
        collectionBinder.setPropertyName( inferredData.getPropertyName() );
        BatchSize batchAnn = property.getAnnotation( BatchSize.class );
        collectionBinder.setBatchSize( batchAnn );
        javax.persistence.OrderBy ejb3OrderByAnn = property.getAnnotation( javax.persistence.OrderBy.class );
        OrderBy orderByAnn = property.getAnnotation( OrderBy.class );
        collectionBinder.setEjb3OrderBy( ejb3OrderByAnn );
        collectionBinder.setSqlOrderBy( orderByAnn );
        Sort sortAnn = property.getAnnotation( Sort.class );
        collectionBinder.setSort( sortAnn );
        Cache cachAnn = property.getAnnotation( Cache.class );
        collectionBinder.setCache( cachAnn );
        collectionBinder.setPropertyHolder( propertyHolder );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        collectionBinder.setIgnoreNotFound( ignoreNotFound );
        collectionBinder.setCollectionType( inferredData.getProperty().getElementClass() );
        collectionBinder.setMappings( mappings );
        collectionBinder.setAccessType( inferredData.getDefaultAccess() );

        Ejb3Column[] elementColumns;
        //do not use "element" if you are a JPA 2 @ElementCollection only for legacy Hibernate mappings
        boolean isJPA2ForValueMapping = property.isAnnotationPresent( ElementCollection.class );
        PropertyData virtualProperty = isJPA2ForValueMapping ? inferredData : new WrappedInferredData(
            inferredData, "element"
        );
        if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
            Formula.class
        ) ) {
          Column ann = property.getAnnotation( Column.class );
          Formula formulaAnn = property.getAnnotation( Formula.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              new Column[] { ann },
              formulaAnn,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else if ( property.isAnnotationPresent( Columns.class ) ) {
          Columns anns = property.getAnnotation( Columns.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              anns.columns(), null, nullability, propertyHolder, virtualProperty,
              entityBinder.getSecondaryTables(), mappings
          );
        }
        else {
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              null,
              null,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        {
          Column[] keyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
          }

          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          //nullify empty array
          keyColumns = keyColumns != null && keyColumns.length > 0 ? keyColumns : null;

          //"mapkey" is the legacy column name of the key column pre JPA 2
          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
              keyColumns,
              null,
              Nullability.FORCED_NOT_NULL,
              propertyHolder,
              isJPA2 ? inferredData : mapKeyVirtualProperty,
              isJPA2 ? "_KEY" : null,
              entityBinder.getSecondaryTables(),
              mappings
          );
          collectionBinder.setMapKeyColumns( mapColumns );
        }
        {
          JoinColumn[] joinKeyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyJoinColumns.class ) ) {
            isJPA2 = Boolean.TRUE;
            final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class )
                .value();
            joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
            int index = 0;
            for ( MapKeyJoinColumn joinColumn : mapKeyJoinColumns ) {
              joinKeyColumns[index] = new MapKeyJoinColumnDelegator( joinColumn );
              index++;
            }
            if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
              throw new AnnotationException(
                  "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
                      + BinderHelper.getPath( propertyHolder, inferredData )
              );
            }
          }
          else if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            joinKeyColumns = new JoinColumn[] {
                new MapKeyJoinColumnDelegator(
                    property.getAnnotation(
                        MapKeyJoinColumn.class
                    )
                )
            };
          }
          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3JoinColumn[] mapJoinColumns = Ejb3JoinColumn.buildJoinColumnsWithDefaultColumnSuffix(
              joinKeyColumns,
              null,
              entityBinder.getSecondaryTables(),
              propertyHolder,
              isJPA2 ? inferredData.getPropertyName() : mapKeyVirtualProperty.getPropertyName(),
              isJPA2 ? "_KEY" : null,
              mappings
          );
          collectionBinder.setMapKeyManyToManyColumns( mapJoinColumns );
        }

        //potential element
        collectionBinder.setEmbedded( property.isAnnotationPresent( Embedded.class ) );
        collectionBinder.setElementColumns( elementColumns );
        collectionBinder.setProperty( property );

        //TODO enhance exception with @ManyToAny and @CollectionOfElements
        if ( oneToManyAnn != null && manyToManyAnn != null ) {
          throw new AnnotationException(
              "@OneToMany and @ManyToMany on the same property is not allowed: "
                  + propertyHolder.getEntityName() + "." + inferredData.getPropertyName()
          );
        }
        String mappedBy = null;
        if ( oneToManyAnn != null ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = oneToManyAnn.mappedBy();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() )
          );
          collectionBinder.setCascadeStrategy(
              getCascadeStrategy(
                  oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
              )
          );
          collectionBinder.setOneToMany( true );
        }
        else if ( elementCollectionAnn != null ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = "";
          final Class<?> targetElement = elementCollectionAnn.targetClass();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( targetElement )
          );
          //collectionBinder.setCascadeStrategy( getCascadeStrategy( embeddedCollectionAnn.cascade(), hibernateCascade ) );
          collectionBinder.setOneToMany( true );
View Full Code Here

Examples of javax.persistence.ElementCollection

          || property.isAnnotationPresent( CollectionOfElements.class ) //legacy Hibernate
          || property.isAnnotationPresent( ElementCollection.class )
          || property.isAnnotationPresent( ManyToAny.class ) ) {
        OneToMany oneToManyAnn = property.getAnnotation( OneToMany.class );
        ManyToMany manyToManyAnn = property.getAnnotation( ManyToMany.class );
        ElementCollection elementCollectionAnn = property.getAnnotation( ElementCollection.class );
        CollectionOfElements collectionOfElementsAnn = property.getAnnotation( CollectionOfElements.class ); //legacy hibernate

        final IndexColumn indexColumn;

        if ( property.isAnnotationPresent( OrderColumn.class ) ) {
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation(OrderColumn.class),
              propertyHolder,
              inferredData,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else {
          //if @IndexColumn is not there, the generated IndexColumn is an implicit column and not used.
          //so we can leave the legacy processing as the default
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation(org.hibernate.annotations.IndexColumn.class),
              propertyHolder,
              inferredData,
              mappings
          );
        }
        CollectionBinder collectionBinder = CollectionBinder.getCollectionBinder(
            propertyHolder.getEntityName(),
            property,
            !indexColumn.isImplicit(),
            property.isAnnotationPresent( CollectionOfElements.class )
            || property.isAnnotationPresent( org.hibernate.annotations.MapKey.class )
                // || property.isAnnotationPresent( ManyToAny.class )
        );
        collectionBinder.setIndexColumn( indexColumn );
        MapKey mapKeyAnn = property.getAnnotation( MapKey.class );
        collectionBinder.setMapKey( mapKeyAnn );
        collectionBinder.setPropertyName( inferredData.getPropertyName() );
        BatchSize batchAnn = property.getAnnotation( BatchSize.class );
        collectionBinder.setBatchSize( batchAnn );
        javax.persistence.OrderBy ejb3OrderByAnn = property.getAnnotation( javax.persistence.OrderBy.class );
        OrderBy orderByAnn = property.getAnnotation( OrderBy.class );
        collectionBinder.setEjb3OrderBy( ejb3OrderByAnn );
        collectionBinder.setSqlOrderBy( orderByAnn );
        Sort sortAnn = property.getAnnotation( Sort.class );
        collectionBinder.setSort( sortAnn );
        Cache cachAnn = property.getAnnotation( Cache.class );
        collectionBinder.setCache( cachAnn );
        collectionBinder.setPropertyHolder( propertyHolder );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        collectionBinder.setIgnoreNotFound( ignoreNotFound );
        collectionBinder.setCollectionType( inferredData.getProperty().getElementClass() );
        collectionBinder.setMappings( mappings );
        collectionBinder.setAccessType( inferredData.getDefaultAccess() );

        Ejb3Column[] elementColumns;
        //do not use "element" if you are a JPA 2 @ElementCollection only for legacy Hibernate mappings
        boolean isJPA2ForValueMapping = property.isAnnotationPresent( ElementCollection.class );
        PropertyData virtualProperty = isJPA2ForValueMapping ? inferredData : new WrappedInferredData( inferredData, "element" );
        if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
            Formula.class
        ) ) {
          Column ann = property.getAnnotation( Column.class );
          Formula formulaAnn = property.getAnnotation( Formula.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              new Column[] { ann },
              formulaAnn,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else if ( property.isAnnotationPresent( Columns.class ) ) {
          Columns anns = property.getAnnotation( Columns.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              anns.columns(), null, nullability, propertyHolder, virtualProperty,
              entityBinder.getSecondaryTables(), mappings
          );
        }
        else {
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              null,
              null,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        {
          Column[] keyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
          }
          else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKey.class ) ) {
            if ( isJPA2 == null) {
              isJPA2 = Boolean.FALSE;
            }
            keyColumns = property.getAnnotation( org.hibernate.annotations.MapKey.class ).columns();
          }

          //not explicitly legacy
          if ( isJPA2 == null) {
            isJPA2 = Boolean.TRUE;
          }

          //nullify empty array
          keyColumns = keyColumns != null && keyColumns.length > 0 ? keyColumns : null;

          //"mapkey" is the legacy column name of the key column pre JPA 2
          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
              keyColumns,
              null,
              Nullability.FORCED_NOT_NULL,
              propertyHolder,
              isJPA2 ? inferredData : mapKeyVirtualProperty,
              isJPA2 ? "_KEY" : null,
              entityBinder.getSecondaryTables(),
              mappings
          );
          collectionBinder.setMapKeyColumns( mapColumns );
        }
        {
          JoinColumn[] joinKeyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyJoinColumns.class ) ) {
            isJPA2 = Boolean.TRUE;
            final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class ).value();
            joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
            int index = 0;
            for ( MapKeyJoinColumn joinColumn : mapKeyJoinColumns ) {
              joinKeyColumns[index] = new MapKeyJoinColumnDelegator( joinColumn );
              index++;
            }
            if ( joinKeyColumns != null ) {
              throw new AnnotationException( "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
                  + BinderHelper.getPath( propertyHolder, inferredData ) );
            }
          }
          else if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            joinKeyColumns = new JoinColumn[] { new MapKeyJoinColumnDelegator( property.getAnnotation( MapKeyJoinColumn.class ) ) };
          }
          else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKeyManyToMany.class ) ) {
            if ( isJPA2 == null) {
              isJPA2 = Boolean.FALSE;
            }
            joinKeyColumns = property.getAnnotation( org.hibernate.annotations.MapKeyManyToMany.class ).joinColumns();
          }

          //not explicitly legacy
          if ( isJPA2 == null) {
            isJPA2 = Boolean.TRUE;
          }

          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3JoinColumn[] mapJoinColumns = Ejb3JoinColumn.buildJoinColumnsWithDefaultColumnSuffix(
              joinKeyColumns,
              null,
              entityBinder.getSecondaryTables(),
              propertyHolder,
              isJPA2 ? inferredData.getPropertyName() : mapKeyVirtualProperty.getPropertyName(),
              isJPA2 ? "_KEY" : null,
              mappings
          );
          collectionBinder.setMapKeyManyToManyColumns( mapJoinColumns );
        }

        //potential element
        collectionBinder.setEmbedded( property.isAnnotationPresent( Embedded.class ) );
        collectionBinder.setElementColumns( elementColumns );
        collectionBinder.setProperty( property );

        //TODO enhance exception with @ManyToAny and @CollectionOfElements
        if ( oneToManyAnn != null && manyToManyAnn != null ) {
          throw new AnnotationException(
              "@OneToMany and @ManyToMany on the same property is not allowed: "
                  + propertyHolder.getEntityName() + "." + inferredData.getPropertyName()
          );
        }
        String mappedBy = null;
        if ( oneToManyAnn != null ) {
          for (Ejb3JoinColumn column : joinColumns) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = oneToManyAnn.mappedBy();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() )
          );
          collectionBinder.setCascadeStrategy(
              getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false) );
          collectionBinder.setOneToMany( true );
        }
        else if ( elementCollectionAnn != null
            || collectionOfElementsAnn != null //Hibernate legacy
            ) {
          for (Ejb3JoinColumn column : joinColumns) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = "";
          final Class<?> targetElement = elementCollectionAnn != null ?
              elementCollectionAnn.targetClass() :
              collectionOfElementsAnn.targetElement();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( targetElement )
          );
          //collectionBinder.setCascadeStrategy( getCascadeStrategy( embeddedCollectionAnn.cascade(), hibernateCascade ) );
View Full Code Here

Examples of javax.persistence.ElementCollection

  private void defineFetchingStrategy() {
    LazyCollection lazy = property.getAnnotation( LazyCollection.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    OneToMany oneToMany = property.getAnnotation( OneToMany.class );
    ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
    ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2
    ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
    FetchType fetchType;
    if ( oneToMany != null ) {
      fetchType = oneToMany.fetch();
    }
    else if ( manyToMany != null ) {
      fetchType = manyToMany.fetch();
    }
    else if ( elementCollection != null ) {
      fetchType = elementCollection.fetch();
    }
    else if ( manyToAny != null ) {
      fetchType = FetchType.LAZY;
    }
    else {
View Full Code Here

Examples of javax.persistence.ElementCollection

    LazyCollection lazy = property.getAnnotation( LazyCollection.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    OneToMany oneToMany = property.getAnnotation( OneToMany.class );
    ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
    CollectionOfElements collectionOfElements = property.getAnnotation( CollectionOfElements.class ); //legacy hibernate
    ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2
    ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
    FetchType fetchType;
    if ( oneToMany != null ) {
      fetchType = oneToMany.fetch();
    }
    else if ( manyToMany != null ) {
      fetchType = manyToMany.fetch();
    }
    else if ( elementCollection != null ) {
      fetchType = elementCollection.fetch();
    }
    else if ( collectionOfElements != null ) {
      fetchType = collectionOfElements.fetch();
    }
    else if ( manyToAny != null ) {
View Full Code Here

Examples of javax.persistence.ElementCollection

          || property.isAnnotationPresent( ManyToMany.class )
          || property.isAnnotationPresent( ElementCollection.class )
          || property.isAnnotationPresent( ManyToAny.class ) ) {
        OneToMany oneToManyAnn = property.getAnnotation( OneToMany.class );
        ManyToMany manyToManyAnn = property.getAnnotation( ManyToMany.class );
        ElementCollection elementCollectionAnn = property.getAnnotation( ElementCollection.class );

        final IndexColumn indexColumn;

        if ( property.isAnnotationPresent( OrderColumn.class ) ) {
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( OrderColumn.class ),
              propertyHolder,
              inferredData,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else {
          //if @IndexColumn is not there, the generated IndexColumn is an implicit column and not used.
          //so we can leave the legacy processing as the default
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( org.hibernate.annotations.IndexColumn.class ),
              propertyHolder,
              inferredData,
              mappings
          );
        }
        CollectionBinder collectionBinder = CollectionBinder.getCollectionBinder(
            propertyHolder.getEntityName(),
            property,
            !indexColumn.isImplicit(),
            property.isAnnotationPresent( MapKeyType.class ),
            mappings
        );
        collectionBinder.setIndexColumn( indexColumn );
        collectionBinder.setMapKey( property.getAnnotation( MapKey.class ) );
        collectionBinder.setPropertyName( inferredData.getPropertyName() );
        BatchSize batchAnn = property.getAnnotation( BatchSize.class );
        collectionBinder.setBatchSize( batchAnn );
        javax.persistence.OrderBy ejb3OrderByAnn = property.getAnnotation( javax.persistence.OrderBy.class );
        OrderBy orderByAnn = property.getAnnotation( OrderBy.class );
        collectionBinder.setEjb3OrderBy( ejb3OrderByAnn );
        collectionBinder.setSqlOrderBy( orderByAnn );
        Sort sortAnn = property.getAnnotation( Sort.class );
        collectionBinder.setSort( sortAnn );
        Cache cachAnn = property.getAnnotation( Cache.class );
        collectionBinder.setCache( cachAnn );
        collectionBinder.setPropertyHolder( propertyHolder );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        collectionBinder.setIgnoreNotFound( ignoreNotFound );
        collectionBinder.setCollectionType( inferredData.getProperty().getElementClass() );
        collectionBinder.setMappings( mappings );
        collectionBinder.setAccessType( inferredData.getDefaultAccess() );

        Ejb3Column[] elementColumns;
        //do not use "element" if you are a JPA 2 @ElementCollection only for legacy Hibernate mappings
        boolean isJPA2ForValueMapping = property.isAnnotationPresent( ElementCollection.class );
        PropertyData virtualProperty = isJPA2ForValueMapping ? inferredData : new WrappedInferredData(
            inferredData, "element"
        );
        if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
            Formula.class
        ) ) {
          Column ann = property.getAnnotation( Column.class );
          Formula formulaAnn = property.getAnnotation( Formula.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              new Column[] { ann },
              formulaAnn,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else if ( property.isAnnotationPresent( Columns.class ) ) {
          Columns anns = property.getAnnotation( Columns.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              anns.columns(), null, nullability, propertyHolder, virtualProperty,
              entityBinder.getSecondaryTables(), mappings
          );
        }
        else {
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              null,
              null,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        {
          Column[] keyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
          }

          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          //nullify empty array
          keyColumns = keyColumns != null && keyColumns.length > 0 ? keyColumns : null;

          //"mapkey" is the legacy column name of the key column pre JPA 2
          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
              keyColumns,
              null,
              Nullability.FORCED_NOT_NULL,
              propertyHolder,
              isJPA2 ? inferredData : mapKeyVirtualProperty,
              isJPA2 ? "_KEY" : null,
              entityBinder.getSecondaryTables(),
              mappings
          );
          collectionBinder.setMapKeyColumns( mapColumns );
        }
        {
          JoinColumn[] joinKeyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyJoinColumns.class ) ) {
            isJPA2 = Boolean.TRUE;
            final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class )
                .value();
            joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
            int index = 0;
            for ( MapKeyJoinColumn joinColumn : mapKeyJoinColumns ) {
              joinKeyColumns[index] = new MapKeyJoinColumnDelegator( joinColumn );
              index++;
            }
            if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
              throw new AnnotationException(
                  "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
                      + BinderHelper.getPath( propertyHolder, inferredData )
              );
            }
          }
          else if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            joinKeyColumns = new JoinColumn[] {
                new MapKeyJoinColumnDelegator(
                    property.getAnnotation(
                        MapKeyJoinColumn.class
                    )
                )
            };
          }
          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3JoinColumn[] mapJoinColumns = Ejb3JoinColumn.buildJoinColumnsWithDefaultColumnSuffix(
              joinKeyColumns,
              null,
              entityBinder.getSecondaryTables(),
              propertyHolder,
              isJPA2 ? inferredData.getPropertyName() : mapKeyVirtualProperty.getPropertyName(),
              isJPA2 ? "_KEY" : null,
              mappings
          );
          collectionBinder.setMapKeyManyToManyColumns( mapJoinColumns );
        }

        //potential element
        collectionBinder.setEmbedded( property.isAnnotationPresent( Embedded.class ) );
        collectionBinder.setElementColumns( elementColumns );
        collectionBinder.setProperty( property );

        //TODO enhance exception with @ManyToAny and @CollectionOfElements
        if ( oneToManyAnn != null && manyToManyAnn != null ) {
          throw new AnnotationException(
              "@OneToMany and @ManyToMany on the same property is not allowed: "
                  + propertyHolder.getEntityName() + "." + inferredData.getPropertyName()
          );
        }
        String mappedBy = null;
        if ( oneToManyAnn != null ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = oneToManyAnn.mappedBy();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() )
          );
          collectionBinder.setCascadeStrategy(
              getCascadeStrategy(
                  oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
              )
          );
          collectionBinder.setOneToMany( true );
        }
        else if ( elementCollectionAnn != null ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = "";
          final Class<?> targetElement = elementCollectionAnn.targetClass();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( targetElement )
          );
          //collectionBinder.setCascadeStrategy( getCascadeStrategy( embeddedCollectionAnn.cascade(), hibernateCascade ) );
          collectionBinder.setOneToMany( true );
View Full Code Here

Examples of javax.persistence.ElementCollection

  private void defineFetchingStrategy() {
    LazyCollection lazy = property.getAnnotation( LazyCollection.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    OneToMany oneToMany = property.getAnnotation( OneToMany.class );
    ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
    ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2
    ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
    FetchType fetchType;
    if ( oneToMany != null ) {
      fetchType = oneToMany.fetch();
    }
    else if ( manyToMany != null ) {
      fetchType = manyToMany.fetch();
    }
    else if ( elementCollection != null ) {
      fetchType = elementCollection.fetch();
    }
    else if ( manyToAny != null ) {
      fetchType = FetchType.LAZY;
    }
    else {
View Full Code Here

Examples of javax.persistence.ElementCollection

          || property.isAnnotationPresent( CollectionOfElements.class ) //legacy Hibernate
          || property.isAnnotationPresent( ElementCollection.class )
          || property.isAnnotationPresent( ManyToAny.class ) ) {
        OneToMany oneToManyAnn = property.getAnnotation( OneToMany.class );
        ManyToMany manyToManyAnn = property.getAnnotation( ManyToMany.class );
        ElementCollection elementCollectionAnn = property.getAnnotation( ElementCollection.class );
        CollectionOfElements collectionOfElementsAnn = property.getAnnotation( CollectionOfElements.class ); //legacy hibernate

        final IndexColumn indexColumn;

        if ( property.isAnnotationPresent( OrderColumn.class ) ) {
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( OrderColumn.class ),
              propertyHolder,
              inferredData,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else {
          //if @IndexColumn is not there, the generated IndexColumn is an implicit column and not used.
          //so we can leave the legacy processing as the default
          indexColumn = IndexColumn.buildColumnFromAnnotation(
              property.getAnnotation( org.hibernate.annotations.IndexColumn.class ),
              propertyHolder,
              inferredData,
              mappings
          );
        }
        CollectionBinder collectionBinder = CollectionBinder.getCollectionBinder(
            propertyHolder.getEntityName(),
            property,
            !indexColumn.isImplicit(),
            property.isAnnotationPresent( CollectionOfElements.class )
                || property.isAnnotationPresent( org.hibernate.annotations.MapKey.class )
            // || property.isAnnotationPresent( ManyToAny.class )
        );
        collectionBinder.setIndexColumn( indexColumn );
        MapKey mapKeyAnn = property.getAnnotation( MapKey.class );
        collectionBinder.setMapKey( mapKeyAnn );
        collectionBinder.setPropertyName( inferredData.getPropertyName() );
        BatchSize batchAnn = property.getAnnotation( BatchSize.class );
        collectionBinder.setBatchSize( batchAnn );
        javax.persistence.OrderBy ejb3OrderByAnn = property.getAnnotation( javax.persistence.OrderBy.class );
        OrderBy orderByAnn = property.getAnnotation( OrderBy.class );
        collectionBinder.setEjb3OrderBy( ejb3OrderByAnn );
        collectionBinder.setSqlOrderBy( orderByAnn );
        Sort sortAnn = property.getAnnotation( Sort.class );
        collectionBinder.setSort( sortAnn );
        Cache cachAnn = property.getAnnotation( Cache.class );
        collectionBinder.setCache( cachAnn );
        collectionBinder.setPropertyHolder( propertyHolder );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        collectionBinder.setIgnoreNotFound( ignoreNotFound );
        collectionBinder.setCollectionType( inferredData.getProperty().getElementClass() );
        collectionBinder.setMappings( mappings );
        collectionBinder.setAccessType( inferredData.getDefaultAccess() );

        Ejb3Column[] elementColumns;
        //do not use "element" if you are a JPA 2 @ElementCollection only for legacy Hibernate mappings
        boolean isJPA2ForValueMapping = property.isAnnotationPresent( ElementCollection.class );
        PropertyData virtualProperty = isJPA2ForValueMapping ? inferredData : new WrappedInferredData(
            inferredData, "element"
        );
        if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
            Formula.class
        ) ) {
          Column ann = property.getAnnotation( Column.class );
          Formula formulaAnn = property.getAnnotation( Formula.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              new Column[] { ann },
              formulaAnn,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        else if ( property.isAnnotationPresent( Columns.class ) ) {
          Columns anns = property.getAnnotation( Columns.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              anns.columns(), null, nullability, propertyHolder, virtualProperty,
              entityBinder.getSecondaryTables(), mappings
          );
        }
        else {
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              null,
              null,
              nullability,
              propertyHolder,
              virtualProperty,
              entityBinder.getSecondaryTables(),
              mappings
          );
        }
        {
          Column[] keyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
          }
          else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKey.class ) ) {
            if ( isJPA2 == null ) {
              isJPA2 = Boolean.FALSE;
            }
            keyColumns = property.getAnnotation( org.hibernate.annotations.MapKey.class ).columns();
          }

          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          //nullify empty array
          keyColumns = keyColumns != null && keyColumns.length > 0 ? keyColumns : null;

          //"mapkey" is the legacy column name of the key column pre JPA 2
          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
              keyColumns,
              null,
              Nullability.FORCED_NOT_NULL,
              propertyHolder,
              isJPA2 ? inferredData : mapKeyVirtualProperty,
              isJPA2 ? "_KEY" : null,
              entityBinder.getSecondaryTables(),
              mappings
          );
          collectionBinder.setMapKeyColumns( mapColumns );
        }
        {
          JoinColumn[] joinKeyColumns = null;
          //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
          Boolean isJPA2 = null;
          if ( property.isAnnotationPresent( MapKeyJoinColumns.class ) ) {
            isJPA2 = Boolean.TRUE;
            final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class )
                .value();
            joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
            int index = 0;
            for ( MapKeyJoinColumn joinColumn : mapKeyJoinColumns ) {
              joinKeyColumns[index] = new MapKeyJoinColumnDelegator( joinColumn );
              index++;
            }
            if ( joinKeyColumns != null ) {
              throw new AnnotationException(
                  "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
                      + BinderHelper.getPath( propertyHolder, inferredData )
              );
            }
          }
          else if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
            isJPA2 = Boolean.TRUE;
            joinKeyColumns = new JoinColumn[] {
                new MapKeyJoinColumnDelegator(
                    property.getAnnotation(
                        MapKeyJoinColumn.class
                    )
                )
            };
          }
          else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKeyManyToMany.class ) ) {
            if ( isJPA2 == null ) {
              isJPA2 = Boolean.FALSE;
            }
            joinKeyColumns = property.getAnnotation( org.hibernate.annotations.MapKeyManyToMany.class )
                .joinColumns();
          }

          //not explicitly legacy
          if ( isJPA2 == null ) {
            isJPA2 = Boolean.TRUE;
          }

          PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
          Ejb3JoinColumn[] mapJoinColumns = Ejb3JoinColumn.buildJoinColumnsWithDefaultColumnSuffix(
              joinKeyColumns,
              null,
              entityBinder.getSecondaryTables(),
              propertyHolder,
              isJPA2 ? inferredData.getPropertyName() : mapKeyVirtualProperty.getPropertyName(),
              isJPA2 ? "_KEY" : null,
              mappings
          );
          collectionBinder.setMapKeyManyToManyColumns( mapJoinColumns );
        }

        //potential element
        collectionBinder.setEmbedded( property.isAnnotationPresent( Embedded.class ) );
        collectionBinder.setElementColumns( elementColumns );
        collectionBinder.setProperty( property );

        //TODO enhance exception with @ManyToAny and @CollectionOfElements
        if ( oneToManyAnn != null && manyToManyAnn != null ) {
          throw new AnnotationException(
              "@OneToMany and @ManyToMany on the same property is not allowed: "
                  + propertyHolder.getEntityName() + "." + inferredData.getPropertyName()
          );
        }
        String mappedBy = null;
        if ( oneToManyAnn != null ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = oneToManyAnn.mappedBy();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() )
          );
          collectionBinder.setCascadeStrategy(
              getCascadeStrategy(
                  oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
              )
          );
          collectionBinder.setOneToMany( true );
        }
        else if ( elementCollectionAnn != null
            || collectionOfElementsAnn != null //Hibernate legacy
            ) {
          for ( Ejb3JoinColumn column : joinColumns ) {
            if ( column.isSecondary() ) {
              throw new NotYetImplementedException( "Collections having FK in secondary table" );
            }
          }
          collectionBinder.setFkJoinColumns( joinColumns );
          mappedBy = "";
          final Class<?> targetElement = elementCollectionAnn != null ?
              elementCollectionAnn.targetClass() :
              collectionOfElementsAnn.targetElement();
          collectionBinder.setTargetEntity(
              mappings.getReflectionManager().toXClass( targetElement )
          );
          //collectionBinder.setCascadeStrategy( getCascadeStrategy( embeddedCollectionAnn.cascade(), hibernateCascade ) );
View Full Code Here

Examples of javax.persistence.ElementCollection

    LazyCollection lazy = property.getAnnotation( LazyCollection.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    OneToMany oneToMany = property.getAnnotation( OneToMany.class );
    ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
    CollectionOfElements collectionOfElements = property.getAnnotation( CollectionOfElements.class ); //legacy hibernate
    ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2
    ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
    FetchType fetchType;
    if ( oneToMany != null ) {
      fetchType = oneToMany.fetch();
    }
    else if ( manyToMany != null ) {
      fetchType = manyToMany.fetch();
    }
    else if ( elementCollection != null ) {
      fetchType = elementCollection.fetch();
    }
    else if ( collectionOfElements != null ) {
      fetchType = collectionOfElements.fetch();
    }
    else if ( manyToAny != null ) {
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.