Package org.hibernate.mapping

Examples of org.hibernate.mapping.OneToOne


  private Property getConstrainedOneToOne(RootClass rc) {
    Iterator propertyClosureIterator = rc.getPropertyClosureIterator();
    while (propertyClosureIterator.hasNext()) {
      Property property = (Property) propertyClosureIterator.next();
      if(property.getValue() instanceof OneToOne) {
        OneToOne oto = (OneToOne) property.getValue();
        if(oto.isConstrained()) {
          return property;
        }
      }
    }
    return null;
View Full Code Here


    private Property bindOneToOne(PersistentClass rc, Table targetTable,
            ForeignKey fk, Set processedColumns, boolean constrained, boolean inverseProperty) {


        OneToOne value = new OneToOne(targetTable, rc);
        value.setReferencedEntityName(revengStrategy
                .tableToClassName(TableIdentifier.create(targetTable)));

        boolean isUnique = isUniqueReference(fk);
        String propertyName = null;
        if(inverseProperty) {
            propertyName = revengStrategy.foreignKeyToInverseEntityName(fk.getName(),
                    TableIdentifier.create(fk.getReferencedTable()), fk
                            .getReferencedColumns(), TableIdentifier
                            .create(targetTable), fk.getColumns(), isUnique);
        } else {
                propertyName = revengStrategy.foreignKeyToEntityName(fk.getName(),
                        TableIdentifier.create(fk.getReferencedTable()), fk
                                .getReferencedColumns(), TableIdentifier
                                .create(targetTable), fk.getColumns(), isUnique);
        }

        Iterator columns = fk.getColumnIterator();
        while (columns.hasNext()) {
            Column fkcolumn = (Column) columns.next();
            checkColumn(fkcolumn);
            value.addColumn(fkcolumn);
            processedColumns.add(fkcolumn);
        }

        value.setFetchMode(FetchMode.SELECT);

        value.setConstrained(constrained);
        value.setForeignKeyType( constrained ?
        ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
        ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );


        return makeEntityProperty(propertyName, true, targetTable, fk, value, inverseProperty);
View Full Code Here

          relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
        }
        bindManyToOne( subnode, (ManyToOne) value, relativePath, isNullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( component.getTable(), component.getOwner() );
        String relativePath;
        if (isEmbedded) {
          relativePath = propertyName;
        }
        else {
View Full Code Here

      else if ( "any".equals( name ) ) {
        value = new Any( table );
        bindAny( subnode, (Any) value, nullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( table, persistentClass );
        bindOneToOne( subnode, (OneToOne) value, propertyName, true, mappings );
      }
      else if ( "property".equals( name ) ) {
        value = new SimpleValue( table );
        bindSimpleValue( subnode, (SimpleValue) value, nullable, propertyName, mappings );
View Full Code Here

    return true;
  }

  public String generateOneToOneAnnotation(Property property, Configuration cfg) {
    OneToOne oneToOne = (OneToOne)property.getValue();

    boolean pkIsAlsoFk = isSharedPkBasedOneToOne(oneToOne);

    AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType("javax.persistence.OneToOne") )
      .addAttribute( "cascade", getCascadeTypes(property))
      .addAttribute( "fetch", getFetchType(property));

    if ( oneToOne.getForeignKeyType().equals(ForeignKeyDirection.FOREIGN_KEY_TO_PARENT) ){
      ab.addQuotedAttribute("mappedBy", getOneToOneMappedBy(cfg, oneToOne));
    }

    StringBuffer buffer = new StringBuffer(ab.getResult());
    buffer.append(getHibernateCascadeTypeAnnotation(property));

    if ( pkIsAlsoFk && oneToOne.getForeignKeyType().equals(ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT) ){
      AnnotationBuilder ab1 = AnnotationBuilder.createAnnotation( importType("javax.persistence.PrimaryKeyJoinColumn") );
      buffer.append(ab1.getResult());
    }

    return buffer.toString();
View Full Code Here

          relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
        }
        bindManyToOne( subnode, (ManyToOne) value, relativePath, isNullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( mappings, component.getTable(), component.getOwner() );
        String relativePath;
        if (isEmbedded) {
          relativePath = propertyName;
        }
        else {
View Full Code Here

      else if ( "any".equals( name ) ) {
        value = new Any( mappings, table );
        bindAny( subnode, (Any) value, nullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( mappings, table, persistentClass );
        bindOneToOne( subnode, (OneToOne) value, propertyName, true, mappings );
      }
      else if ( "property".equals( name ) ) {
        value = new SimpleValue( mappings, table );
        bindSimpleValue( subnode, (SimpleValue) value, nullable, propertyName, mappings );
View Full Code Here

          relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
        }
        bindManyToOne( subnode, (ManyToOne) value, relativePath, isNullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( component.getTable(), component.getOwner() );
        String relativePath;
        if (isEmbedded) {
          relativePath = propertyName;
        }
        else {
View Full Code Here

      else if ( "any".equals( name ) ) {
        value = new Any( table );
        bindAny( subnode, (Any) value, nullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( table, persistentClass );
        bindOneToOne( subnode, (OneToOne) value, propertyName, true, mappings );
      }
      else if ( "property".equals( name ) ) {
        value = new SimpleValue( table );
        bindSimpleValue( subnode, (SimpleValue) value, nullable, propertyName, mappings );
View Full Code Here

          relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
        }
        bindManyToOne( subnode, (ManyToOne) value, relativePath, isNullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( component.getTable(), component.getOwner() );
        String relativePath;
        if (isEmbedded) {
          relativePath = propertyName;
        }
        else {
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.OneToOne

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.