Package org.hibernate.mapping

Examples of org.hibernate.mapping.Collection


    return this;
  }

  public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String region)
      throws MappingException {
    Collection collection = getCollectionMapping( collectionRole );
    if ( collection == null ) {
      throw new MappingException( "Cannot cache an unknown collection: " + collectionRole );
    }
    collection.setCacheConcurrencyStrategy( concurrencyStrategy );
    collection.setCacheRegionName( region );
  }
View Full Code Here


        .qualify( path, propertyName );

      CollectionType collectType = CollectionType.collectionTypeFromString( name );
      Value value = null;
      if ( collectType != null ) {
        Collection collection = collectType.create(
            subnode,
            subpath,
            component.getOwner(),
            mappings, inheritedMetas
          );
View Full Code Here

      String propertyName = subnode.attributeValue( "name" );

      CollectionType collectType = CollectionType.collectionTypeFromString( name );
      Value value = null;
      if ( collectType != null ) {
        Collection collection = collectType.create(
            subnode,
            StringHelper.qualify( entityName, propertyName ),
            persistentClass,
            mappings, inheritedMetas
          );
View Full Code Here

      if ( propertyRef != null ) {
        mappings.addUniquePropertyReference( toOne.getReferencedEntityName(), propertyRef );
      }
    }
    else if ( value instanceof Collection ) {
      Collection coll = (Collection) value;
      String propertyRef = coll.getReferencedPropertyName();
      // not necessarily a *unique* property reference
      if ( propertyRef != null ) {
        mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef );
      }
    }

    value.createForeignKey();
    Property prop = new Property();
View Full Code Here

        ib.setValue( list.getIndex() );
        referenced.addProperty( ib );
      }
    }
    else {
      Collection coll = this.collection;
      throw new AnnotationException(
          "List/array has to be annotated with an @OrderColumn (or @IndexColumn): "
              + coll.getRole()
      );
    }
  }
View Full Code Here

      LOG.debugf( "Retrieving property %s.%s", associatedClass.getEntityName(), mappedByProperty );

      final Property property = associatedClass.getRecursiveProperty( columns[0].getMappedBy() );
      Iterator mappedByColumns;
      if ( property.getValue() instanceof Collection ) {
        Collection collection = ( (Collection) property.getValue() );
        Value element = collection.getElement();
        if ( element == null ) {
          throw new AnnotationException(
              "Illegal use of mappedBy on both sides of the relationship: "
                  + associatedClass.getEntityName() + "." + mappedByProperty
          );
        }
        mappedByColumns = element.getColumnIterator();
      }
      else {
        mappedByColumns = property.getValue().getColumnIterator();
      }
      while ( mappedByColumns.hasNext() ) {
        Column column = (Column) mappedByColumns.next();
        columns[0].overrideFromReferencedColumnIfNecessary( column );
        columns[0].linkValueUsingAColumnCopy( column, value );
      }
    }
    else if ( columns[0].isImplicit() ) {
      /**
       * if columns are implicit, then create the columns based on the
       * referenced entity id columns
       */
      Iterator idColumns;
      if ( referencedEntity instanceof JoinedSubclass ) {
        idColumns = referencedEntity.getKey().getColumnIterator();
      }
      else {
        idColumns = referencedEntity.getIdentifier().getColumnIterator();
      }
      while ( idColumns.hasNext() ) {
        Column column = (Column) idColumns.next();
        columns[0].overrideFromReferencedColumnIfNecessary( column );
        columns[0].linkValueUsingDefaultColumnNaming( column, referencedEntity, value );
      }
    }
    else {
      int fkEnum = Ejb3JoinColumn.checkReferencedColumnsType( columns, referencedEntity, mappings );

      if ( Ejb3JoinColumn.NON_PK_REFERENCE == fkEnum ) {
        String referencedPropertyName;
        if ( value instanceof ToOne ) {
          referencedPropertyName = ( (ToOne) value ).getReferencedPropertyName();
        }
        else if ( value instanceof DependantValue ) {
          String propertyName = columns[0].getPropertyName();
          if ( propertyName != null ) {
            Collection collection = (Collection) referencedEntity.getRecursiveProperty( propertyName )
                .getValue();
            referencedPropertyName = collection.getReferencedPropertyName();
          }
          else {
            throw new AnnotationException( "SecondaryTable JoinColumn cannot reference a non primary key" );
          }

View Full Code Here

    Map<String,Set<String>> tmpEntityToCollectionRoleMap = new HashMap<String,Set<String>>();
    collectionPersisters = new HashMap<String,CollectionPersister>();
    Map<String,CollectionMetadata> tmpCollectionMetadata = new HashMap<String,CollectionMetadata>();
    Iterator collections = cfg.getCollectionMappings();
    while ( collections.hasNext() ) {
      Collection model = (Collection) collections.next();
      final String cacheRegionName = cacheRegionPrefix + model.getCacheRegionName();
      final AccessType accessType = AccessType.fromExternalName( model.getCacheConcurrencyStrategy() );
      CollectionRegionAccessStrategy accessStrategy = null;
      if ( accessType != null && settings.isSecondLevelCacheEnabled() ) {
        LOG.tracev( "Building shared cache region for collection data [{0}]", model.getRole() );
        CollectionRegion collectionRegion = regionFactory.buildCollectionRegion( cacheRegionName, properties, CacheDataDescriptionImpl
            .decode( model ) );
        accessStrategy = collectionRegion.buildAccessStrategy( accessType );
        entityAccessStrategies.put( cacheRegionName, accessStrategy );
        cacheAccess.addCacheRegion( cacheRegionName, collectionRegion );
      }
      CollectionPersister persister = persisterFactory.createCollectionPersister(
          cfg,
          model,
          accessStrategy,
          this
      ) ;
      collectionPersisters.put( model.getRole(), persister );
      tmpCollectionMetadata.put( model.getRole(), persister.getCollectionMetadata() );
      Type indexType = persister.getIndexType();
      if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
        String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this );
        Set roles = tmpEntityToCollectionRoleMap.get( entityName );
        if ( roles == null ) {
View Full Code Here

  public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String region) {
    caches.add( new CacheHolder( collectionRole, concurrencyStrategy, region, false, false ) );
  }

  private void applyCollectionCacheConcurrencyStrategy(CacheHolder holder) {
    Collection collection = getCollectionMapping( holder.role );
    if ( collection == null ) {
      throw new MappingException( "Cannot cache an unknown collection: " + holder.role );
    }
    collection.setCacheConcurrencyStrategy( holder.usage );
    collection.setCacheRegionName( holder.region );
  }
View Full Code Here

   */
  private Property bindOneToMany(PersistentClass rc, ForeignKey foreignKey, Set processed, Mapping mapping) {

    Table collectionTable = foreignKey.getTable();

    Collection collection = new org.hibernate.mapping.Set(mappings, rc); // MASTER TODO: allow overriding collection type

    collection.setCollectionTable(collectionTable); // CHILD+



    boolean manyToMany = revengStrategy.isManyToManyTable( collectionTable );
    if(manyToMany) {
      //log.debug("Rev.eng said here is a many-to-many");
      // TODO: handle "the other side should influence the name"
    }



        if(manyToMany) {

          ManyToOne element = new ManyToOne(mappings, collection.getCollectionTable());
          //TODO: find the other foreignkey and choose the other side.
          Iterator foreignKeyIterator = foreignKey.getTable().getForeignKeyIterator();
          List keys = new ArrayList();
          while ( foreignKeyIterator.hasNext() ) {
        Object next = foreignKeyIterator.next();
        if(next!=foreignKey) {
          keys.add(next);
        }
      }

          if(keys.size()>1) {
            throw new JDBCBinderException("more than one other foreign key to choose from!"); // todo: handle better ?
          }

          ForeignKey fk = (ForeignKey) keys.get( 0 );

          String tableToClassName = bindCollection( rc, foreignKey, fk, collection );

      element.setReferencedEntityName( tableToClassName );
      element.addColumn( fk.getColumn( 0 ) );
      collection.setElement( element );

        } else {
          String tableToClassName = bindCollection( rc, foreignKey, null, collection );

          OneToMany oneToMany = new OneToMany(mappings, collection.getOwner());

      oneToMany.setReferencedEntityName( tableToClassName ); // Child
          mappings.addSecondPass( new JDBCCollectionSecondPass(mappings, collection) );

          collection.setElement(oneToMany);
        }
    // bind keyvalue
    KeyValue referencedKeyValue;
    String propRef = collection.getReferencedPropertyName();
    if (propRef==null) {
      referencedKeyValue = collection.getOwner().getIdentifier();
    }
    else {
      referencedKeyValue = (KeyValue) collection.getOwner()
        .getProperty(propRef)
        .getValue();
    }

    SimpleValue keyValue = new DependantValue(mappings, collectionTable, referencedKeyValue);
    //keyValue.setForeignKeyName("none"); // Avoid creating the foreignkey
    //key.setCascadeDeleteEnabled( "cascade".equals( subnode.attributeValue("on-delete") ) );
    Iterator columnIterator = foreignKey.getColumnIterator();
    while ( columnIterator.hasNext() ) {
      Column fkcolumn = (Column) columnIterator.next();
      if(fkcolumn.getSqlTypeCode()!=null) { // TODO: user defined foreign ref columns does not have a type set.
        guessAndAlignType(collectionTable, fkcolumn, mapping, false); // needed to ensure foreign key columns has same type as the "property" column.
      }
      keyValue.addColumn( fkcolumn );
    }

    collection.setKey(keyValue);

    mappings.addCollection(collection);

    return makeCollectionProperty(StringHelper.unqualify( collection.getRole() ), true, rc.getTable(), foreignKey, collection, true);
    //return makeProperty(TableIdentifier.create( rc.getTable() ), StringHelper.unqualify( collection.getRole() ), collection, true, true, true, "none", null); // TODO: cascade isn't all by default


  }
View Full Code Here

      }
    }

    iter = collections.values().iterator();
    while ( iter.hasNext() ) {
      Collection collection = (Collection) iter.next();

      if ( collection.isIdentified() ) {

        IdentifierGenerator ig = ( (IdentifierCollection) collection ).getIdentifier()
            .createIdentifierGenerator(
                dialect,
                defaultCatalog,
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Collection

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.