Package org.hibernate.mapping

Examples of org.hibernate.mapping.Join


      SecondaryTable secondaryTable,
      JoinTable joinTable,
      PropertyHolder propertyHolder,
      boolean noDelayInPkColumnCreation) {
    // A non null propertyHolder means than we process the Pk creation without delay
    Join join = new Join();
    join.setPersistentClass( persistentClass );

    final String schema;
    final String catalog;
    final SecondaryTableNameSource secondaryTableNameContext;
    final Object joinColumns;
    final List<UniqueConstraintHolder> uniqueConstraintHolders;

    if ( secondaryTable != null ) {
      schema = secondaryTable.schema();
      catalog = secondaryTable.catalog();
      secondaryTableNameContext = new SecondaryTableNameSource( secondaryTable.name() );
      joinColumns = secondaryTable.pkJoinColumns();
      uniqueConstraintHolders = TableBinder.buildUniqueConstraintHolders( secondaryTable.uniqueConstraints() );
    }
    else if ( joinTable != null ) {
      schema = joinTable.schema();
      catalog = joinTable.catalog();
      secondaryTableNameContext = new SecondaryTableNameSource( joinTable.name() );
      joinColumns = joinTable.joinColumns();
      uniqueConstraintHolders = TableBinder.buildUniqueConstraintHolders( joinTable.uniqueConstraints() );
    }
    else {
      throw new AssertionFailure( "Both JoinTable and SecondaryTable are null" );
    }

    final Table table = TableBinder.buildAndFillTable(
        schema,
        catalog,
        secondaryTableNameContext,
        SEC_TBL_NS_HELPER,
        false,
        uniqueConstraintHolders,
        null,
        null,
        mappings,
        null
    );

    //no check constraints available on joins
    join.setTable( table );

    //somehow keep joins() for later.
    //Has to do the work later because it needs persistentClass id!
    log.info(
        "Adding secondary table to entity {} -> {}", persistentClass.getEntityName(), join.getTable().getName()
    );
    org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation( join );
    if ( matchingTable != null ) {
      join.setSequentialSelect( FetchMode.JOIN != matchingTable.fetch() );
      join.setInverse( matchingTable.inverse() );
      join.setOptional( matchingTable.optional() );
      if ( !BinderHelper.isEmptyAnnotationValue( matchingTable.sqlInsert().sql() ) ) {
        join.setCustomSQLInsert( matchingTable.sqlInsert().sql().trim(),
            matchingTable.sqlInsert().callable(),
            ExecuteUpdateResultCheckStyle.parse( matchingTable.sqlInsert().check().toString().toLowerCase() )
        );
      }
      if ( !BinderHelper.isEmptyAnnotationValue( matchingTable.sqlUpdate().sql() ) ) {
        join.setCustomSQLUpdate( matchingTable.sqlUpdate().sql().trim(),
            matchingTable.sqlUpdate().callable(),
            ExecuteUpdateResultCheckStyle.parse( matchingTable.sqlUpdate().check().toString().toLowerCase() )
        );
      }
      if ( !BinderHelper.isEmptyAnnotationValue( matchingTable.sqlDelete().sql() ) ) {
        join.setCustomSQLDelete( matchingTable.sqlDelete().sql().trim(),
            matchingTable.sqlDelete().callable(),
            ExecuteUpdateResultCheckStyle.parse( matchingTable.sqlDelete().check().toString().toLowerCase() )
        );
      }
    }
    else {
      //default
      join.setSequentialSelect( false );
      join.setInverse( false );
      join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway
    }

    if ( noDelayInPkColumnCreation ) {
      createPrimaryColumnsToSecondaryTable( joinColumns, propertyHolder, join );
    }
View Full Code Here


        Map<Join, Element> joinElements = new HashMap<Join, Element>();
        entitiesJoins.put(pc.getEntityName(), joinElements);

        while (joins.hasNext()) {
            Join join = joins.next();

      // Checking if all of the join properties are audited
      if (!checkPropertiesAudited(join.getPropertyIterator(), auditingData)) {
        continue;
      }

            // Determining the table name. If there is no entry in the dictionary, just constructing the table name
            // as if it was an entity (by appending/prepending configured strings).
            String originalTableName = join.getTable().getName();
            String auditTableName = auditingData.getSecondaryTableDictionary().get(originalTableName);
            if (auditTableName == null) {
                auditTableName = verEntCfg.getAuditEntityName(originalTableName);
            }

            String schema = getSchema(auditingData.getAuditTable().schema(), join.getTable());
            String catalog = getCatalog(auditingData.getAuditTable().catalog(), join.getTable());

            Element joinElement = MetadataTools.createJoin(parent, auditTableName, schema, catalog);
            joinElements.put(join, joinElement);

            Element joinKey = joinElement.addElement("key");
            MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
            MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, 0, 0, null, null, null);
        }
    }
View Full Code Here

    private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, ClassAuditingData auditingData,
                          String entityName, EntityXmlMappingData xmlMappingData,boolean firstPass) {
        Iterator<Join> joins = pc.getJoinIterator();

        while (joins.hasNext()) {
            Join join = joins.next();
            Element joinElement = entitiesJoins.get(entityName).get(join);

      if (joinElement != null) {
              addProperties(joinElement, join.getPropertyIterator(), currentMapper, auditingData, entityName,
                      xmlMappingData, firstPass);
      }
        }
    }
View Full Code Here

        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        final boolean mandatory = !ann.optional() || forcePersist;
        bindManyToOne(
            getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ),
            joinColumns,
            !mandatory,
            ignoreNotFound, onDeleteCascade,
            ToOneBinder.getTargetEntity( inferredData, mappings ),
            propertyHolder,
            inferredData, false, isIdentifierMapper,
            inSecondPass, propertyBinder, mappings
        );
      }
      else if ( property.isAnnotationPresent( OneToOne.class ) ) {
        OneToOne ann = property.getAnnotation( OneToOne.class );

        //check validity
        if ( property.isAnnotationPresent( Column.class )
            || property.isAnnotationPresent( Columns.class ) ) {
          throw new AnnotationException(
              "@Column(s) not allowed on a @OneToOne property: "
                  + BinderHelper.getPath( propertyHolder, inferredData )
          );
        }

        //FIXME support a proper PKJCs
        boolean trueOneToOne = property.isAnnotationPresent( PrimaryKeyJoinColumn.class )
            || property.isAnnotationPresent( PrimaryKeyJoinColumns.class );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        //MapsId means the columns belong to the pk => not null
        //@PKJC must be constrained
        final boolean mandatory = !ann.optional() || forcePersist || trueOneToOne;
        bindOneToOne(
            getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ),
            joinColumns,
            !mandatory,
            getFetchMode( ann.fetch() ),
            ignoreNotFound, onDeleteCascade,
            ToOneBinder.getTargetEntity( inferredData, mappings ),
            propertyHolder,
            inferredData,
            ann.mappedBy(),
            trueOneToOne,
            isIdentifierMapper,
            inSecondPass,
            propertyBinder,
            mappings
        );
      }
      else if ( property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {

        //check validity
        if ( property.isAnnotationPresent( Column.class )
            || property.isAnnotationPresent( Columns.class ) ) {
          throw new AnnotationException(
              "@Column(s) not allowed on a @Any property: "
                  + BinderHelper.getPath( propertyHolder, inferredData )
          );
        }

        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        bindAny(
            getCascadeStrategy( null, hibernateCascade, false, forcePersist ),
            //@Any has not cascade attribute
View Full Code Here

        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        final boolean mandatory = !ann.optional() || forcePersist;
        bindManyToOne(
            getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ),
            joinColumns,
            !mandatory,
            ignoreNotFound, onDeleteCascade,
            ToOneBinder.getTargetEntity( inferredData, mappings ),
            propertyHolder,
            inferredData, false, isIdentifierMapper,
            inSecondPass, propertyBinder, mappings
        );
      }
      else if ( property.isAnnotationPresent( OneToOne.class ) ) {
        OneToOne ann = property.getAnnotation( OneToOne.class );

        //check validity
        if ( property.isAnnotationPresent( Column.class )
            || property.isAnnotationPresent( Columns.class ) ) {
          throw new AnnotationException(
              "@Column(s) not allowed on a @OneToOne property: "
                  + BinderHelper.getPath( propertyHolder, inferredData )
          );
        }

        //FIXME support a proper PKJCs
        boolean trueOneToOne = property.isAnnotationPresent( PrimaryKeyJoinColumn.class )
            || property.isAnnotationPresent( PrimaryKeyJoinColumns.class );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        //MapsId means the columns belong to the pk => not null
        //@PKJC must be constrained
          final boolean mandatory = !ann.optional() || forcePersist || trueOneToOne;
       
        bindOneToOne(
            getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ),
            joinColumns,
            !mandatory,
            getFetchMode( ann.fetch() ),
            ignoreNotFound, onDeleteCascade,
            ToOneBinder.getTargetEntity( inferredData, mappings ),
            propertyHolder,
            inferredData,
            ann.mappedBy(),
            trueOneToOne,
            isIdentifierMapper,
            inSecondPass,
            propertyBinder,
            mappings
        );
      }
      else if ( property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {

        //check validity
        if ( property.isAnnotationPresent( Column.class )
            || property.isAnnotationPresent( Columns.class ) ) {
          throw new AnnotationException(
              "@Column(s) not allowed on a @Any property: "
                  + BinderHelper.getPath( propertyHolder, inferredData )
          );
        }

        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        bindAny(
            getCascadeStrategy( null, hibernateCascade, false, forcePersist ),
            //@Any has not cascade attribute
View Full Code Here

      boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
      OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
      boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
      JoinTable assocTable = property.getAnnotation( JoinTable.class );
      if ( assocTable != null ) {
        Join join = propertyHolder.addJoin( assocTable, false );
        for (Ejb3JoinColumn joinColumn : joinColumns) {
          joinColumn.setSecondaryTableName( join.getTable().getName() );
        }
      }
      bindManyToOne(
          getCascadeStrategy( ann.cascade(), hibernateCascade ),
          joinColumns,
          ann.optional(),
          ignoreNotFound, onDeleteCascade,
          mappings.getReflectionManager().toXClass( ann.targetEntity() ),
          propertyHolder,
          inferredData, false, isIdentifierMapper, inSecondPass, mappings
      );
    }
    else if ( property.isAnnotationPresent( OneToOne.class ) ) {
      OneToOne ann = property.getAnnotation( OneToOne.class );

      //check validity
      if ( property.isAnnotationPresent( Column.class )
          || property.isAnnotationPresent( Columns.class ) ) {
        throw new AnnotationException( "@Column(s) not allowed on a @OneToOne property: "
            + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) );
      }

      //FIXME support a proper PKJCs
      boolean trueOneToOne = property.isAnnotationPresent( PrimaryKeyJoinColumn.class )
          || property.isAnnotationPresent( PrimaryKeyJoinColumns.class );
      Cascade hibernateCascade = property.getAnnotation( Cascade.class );
      NotFound notFound = property.getAnnotation( NotFound.class );
      boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
      OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
      boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
      JoinTable assocTable = property.getAnnotation( JoinTable.class );
      if ( assocTable != null ) {
        Join join = propertyHolder.addJoin( assocTable, false );
        for (Ejb3JoinColumn joinColumn : joinColumns) {
          joinColumn.setSecondaryTableName( join.getTable().getName() );
        }
      }
      bindOneToOne(
          getCascadeStrategy( ann.cascade(), hibernateCascade ),
          joinColumns,
          ann.optional(),
          getFetchMode( ann.fetch() ),
          ignoreNotFound, onDeleteCascade,
          mappings.getReflectionManager().toXClass( ann.targetEntity() ),
          propertyHolder,
          inferredData, ann.mappedBy(), trueOneToOne, isIdentifierMapper, inSecondPass, mappings
      );
    }
    else if ( property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {

      //check validity
      if ( property.isAnnotationPresent( Column.class )
          || property.isAnnotationPresent( Columns.class ) ) {
        throw new AnnotationException( "@Column(s) not allowed on a @Any property: "
            + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) );
      }

      Cascade hibernateCascade = property.getAnnotation( Cascade.class );
      NotFound notFound = property.getAnnotation( NotFound.class );
      boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
      OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
      boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
      JoinTable assocTable = property.getAnnotation( JoinTable.class );
      if ( assocTable != null ) {
        Join join = propertyHolder.addJoin( assocTable, false );
        for (Ejb3JoinColumn joinColumn : joinColumns) {
          joinColumn.setSecondaryTableName( join.getTable().getName() );
        }
      }
      bindAny( getCascadeStrategy( null, hibernateCascade ), //@Any has not cascade attribute
          joinColumns, onDeleteCascade, nullability,
          propertyHolder, inferredData, entityBinder,
View Full Code Here

        Map<Join, Element> joinElements = new HashMap<Join, Element>();
        entitiesJoins.put(pc.getEntityName(), joinElements);

        while (joins.hasNext()) {
            Join join = joins.next();

      // Checking if all of the join properties are audited
      if (!checkPropertiesAudited(join.getPropertyIterator(), auditingData)) {
        continue;
      }

            // Determining the table name. If there is no entry in the dictionary, just constructing the table name
            // as if it was an entity (by appending/prepending configured strings).
            String originalTableName = join.getTable().getName();
            String auditTableName = auditingData.getSecondaryTableDictionary().get(originalTableName);
            if (auditTableName == null) {
                auditTableName = verEntCfg.getAuditEntityName(originalTableName);
            }

            String schema = getSchema(auditingData.getAuditTable().schema(), join.getTable());
            String catalog = getCatalog(auditingData.getAuditTable().catalog(), join.getTable());

            Element joinElement = MetadataTools.createJoin(parent, auditTableName, schema, catalog);
            joinElements.put(join, joinElement);

            Element joinKey = joinElement.addElement("key");
            MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
            MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, 0, 0, null, null, null);
        }
    }
View Full Code Here

    private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, ClassAuditingData auditingData,
                          String entityName, EntityXmlMappingData xmlMappingData,boolean firstPass) {
        Iterator<Join> joins = pc.getJoinIterator();

        while (joins.hasNext()) {
            Join join = joins.next();
            Element joinElement = entitiesJoins.get(entityName).get(join);

      if (joinElement != null) {
              addProperties(joinElement, join.getPropertyIterator(), currentMapper, auditingData, entityName,
                      xmlMappingData, firstPass);
      }
        }
    }
View Full Code Here

* @author Emmanuel Bernard
*/
public class JoinTest extends TestCase {

  public void testDefaultValue() throws Exception {
    Join join = (Join) getCfg().getClassMapping( Life.class.getName() ).getJoinClosureIterator().next();
    assertEquals( "ExtendedLife", join.getTable().getName() );
    org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column();
    owner.setName( "LIFE_ID" );
    assertTrue( join.getTable().getPrimaryKey().containsColumn( owner ) );
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Life life = new Life();
    life.duration = 15;
    life.fullDescription = "Long long description";
View Full Code Here

    tx.commit();
    s.close();
  }

  public void testCompositePK() throws Exception {
    Join join = (Join) getCfg().getClassMapping( Dog.class.getName() ).getJoinClosureIterator().next();
    assertEquals( "DogThoroughbred", join.getTable().getName() );
    org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column();
    owner.setName( "OWNER_NAME" );
    assertTrue( join.getTable().getPrimaryKey().containsColumn( owner ) );
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Dog dog = new Dog();
    DogPk id = new DogPk();
    id.name = "Thalie";
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Join

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.