Package org.hibernate.mapping

Examples of org.hibernate.mapping.Component$ValueGenerationPlan


            mappings
          );
        bindManyToManySubelements( collection, subnode, mappings );
      }
      else if ( "composite-element".equals( name ) ) {
        Component element = new Component( collection );
        collection.setElement( element );
        bindComposite(
            subnode,
            element,
            collection.getRole() + ".element",
View Full Code Here


    }
    else {
      proxyFactory = null;
    }
   
    Component mapper = mappingInfo.getIdentifierMapper();
    identifierMapperType = mapper==null ? null : (AbstractComponentType) mapper.getType();
  }
View Full Code Here

    while ( propertyIterator.hasNext() ) {

      Property prop = ( Property ) propertyIterator.next();
      String propname = path == null ? prop.getName() : path + "." + prop.getName();
      if ( prop.isComposite() ) {
        Component component = ( Component ) prop.getValue();
        Iterator compProps = component.getPropertyIterator();
        internalInitSubclassPropertyAliasesMap( propname, compProps );
      }
      else {
        String[] aliases = new String[prop.getColumnSpan()];
        String[] cols = new String[prop.getColumnSpan()];
View Full Code Here

      case ENTITY: {
        final org.hibernate.type.EntityType type = (EntityType) typeContext.getValue().getType();
        return (Type<Y>) context.locateEntityType( type.getAssociatedEntityName() );
      }
      case EMBEDDABLE: {
        final Component component = (Component) typeContext.getValue();
        final EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<Y>(
            typeContext.getBindableType(),
            typeContext.getAttributeMetadata().getOwnerType(),
            (ComponentType) typeContext.getValue().getType()
        );
        context.registerEmbeddedableType( embeddableType );
        final Iterator<Property> subProperties = component.getPropertyIterator();
        while ( subProperties.hasNext() ) {
          final Property property = subProperties.next();
          final AttributeImplementor<Y, Object> attribute = buildAttribute( embeddableType, property );
          if ( attribute != null ) {
            embeddableType.getBuilder().addAttribute( attribute );
View Full Code Here

    while ( propertyIterator.hasNext() ) {

      Property prop = ( Property ) propertyIterator.next();
      String propname = path == null ? prop.getName() : path + "." + prop.getName();
      if ( prop.isComposite() ) {
        Component component = ( Component ) prop.getValue();
        Iterator compProps = component.getPropertyIterator();
        internalInitSubclassPropertyAliasesMap( propname, compProps );
      }
      else {
        String[] aliases = new String[prop.getColumnSpan()];
        String[] cols = new String[prop.getColumnSpan()];
View Full Code Here

      jpaEntityType.getBuilder().applyIdClassAttributes( attributes );
    }
    else {
      final KeyValue value = persistentClass.getIdentifier();
      if (value instanceof Component ) {
        final Component component = ( Component ) value;
        if ( component.getPropertySpan() > 1 ) {
          //FIXME we are an Hibernate embedded id (ie not type)
        }
        else {
          //FIXME take care of declared vs non declared property
          jpaEntityType.getBuilder().applyIdAttribute(
            attributeFactory.buildIdAttribute(
                jpaEntityType,
                (Property) component.getPropertyIterator().next() )
          );
        }
      }
    }
  }
View Full Code Here

      );
      propertyHolder.setInIdClass( null );
      inferredData = new PropertyPreloadedData(
          propertyAccessor, PropertyPath.IDENTIFIER_MAPPER_PROPERTY, compositeClass
      );
      Component mapper = fillComponent(
          propertyHolder,
          inferredData,
          baseInferredData,
          propertyAccessor,
          false,
          entityBinder,
          true,
          true,
          false,
          mappings,
          inheritanceStatePerClass
      );
      entityBinder.setIgnoreIdAnnotations( ignoreIdAnnotations );
      persistentClass.setIdentifierMapper( mapper );

      //If id definition is on a mapped superclass, update the mapping
      final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
          classWithIdClass,
          inheritanceStatePerClass,
          mappings
      );
      if ( superclass != null ) {
        superclass.setDeclaredIdentifierMapper( mapper );
      }
      else {
        //we are for sure on the entity
        persistentClass.setDeclaredIdentifierMapper( mapper );
      }

      Property property = new Property();
      property.setName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY );
      property.setNodeName( "id" );
      property.setUpdateable( false );
      property.setInsertable( false );
      property.setValue( mapper );
      property.setPropertyAccessorName( "embedded" );
      persistentClass.addProperty( property );
      entityBinder.setIgnoreIdAnnotations( true );

      Iterator properties = mapper.getPropertyIterator();
      while ( properties.hasNext() ) {
        idPropertiesIfIdClass.add( ( ( Property ) properties.next() ).getName() );
      }
      return true;
    }
View Full Code Here

      boolean isComponentEmbedded,
      boolean isId, //is a identifier
      Map<XClass, InheritanceState> inheritanceStatePerClass,
      String referencedEntityName, //is a component who is overridden by a @MapsId
      Ejb3JoinColumn[] columns) {
    Component comp;
    if ( referencedEntityName != null ) {
      comp = createComponent( propertyHolder, inferredData, isComponentEmbedded, isIdentifierMapper, mappings );
      SecondPass sp = new CopyIdentifierComponentSecondPass(
          comp,
          referencedEntityName,
          columns,
          mappings
      );
      mappings.addSecondPass( sp );
    }
    else {
      comp = fillComponent(
          propertyHolder, inferredData, propertyAccessor, !isId, entityBinder,
          isComponentEmbedded, isIdentifierMapper,
          false, mappings, inheritanceStatePerClass
      );
    }
    if ( isId ) {
      comp.setKey( true );
      if ( propertyHolder.getPersistentClass().getIdentifier() != null ) {
        throw new AnnotationException(
            comp.getComponentClassName()
                + " must not have @Id properties when used as an @EmbeddedId: "
                + BinderHelper.getPath( propertyHolder, inferredData )
        );
      }
      if ( referencedEntityName == null && comp.getPropertySpan() == 0 ) {
        throw new AnnotationException(
            comp.getComponentClassName()
                + " has no persistent id property: "
                + BinderHelper.getPath( propertyHolder, inferredData )
        );
      }
    }
View Full Code Here

    /**
     * inSecondPass can only be used to apply right away the second pass of a composite-element
     * Because it's a value type, there is no bidirectional association, hence second pass
     * ordering does not matter
     */
    Component comp = createComponent( propertyHolder, inferredData, isComponentEmbedded, isIdentifierMapper, mappings );
    String subpath = BinderHelper.getPath( propertyHolder, inferredData );
    LOG.tracev( "Binding component with path: {0}", subpath );
    PropertyHolder subHolder = PropertyHolderBuilder.buildPropertyHolder(
        comp,
        subpath,
        inferredData,
        propertyHolder,
        mappings
    );


    // propertyHolder here is the owner of the component property.  Tell it we are about to start the component...

    propertyHolder.startingProperty( inferredData.getProperty() );

    final XClass xClassProcessed = inferredData.getPropertyClass();
    List<PropertyData> classElements = new ArrayList<PropertyData>();
    XClass returnedClassOrElement = inferredData.getClassOrElement();

    List<PropertyData> baseClassElements = null;
    Map<String, PropertyData> orderedBaseClassElements = new HashMap<String, PropertyData>();
    XClass baseReturnedClassOrElement;
    if ( baseInferredData != null ) {
      baseClassElements = new ArrayList<PropertyData>();
      baseReturnedClassOrElement = baseInferredData.getClassOrElement();
      bindTypeDefs( baseReturnedClassOrElement, mappings );
      PropertyContainer propContainer = new PropertyContainer( baseReturnedClassOrElement, xClassProcessed );
      addElementsOfClass( baseClassElements, propertyAccessor, propContainer, mappings );
      for ( PropertyData element : baseClassElements ) {
        orderedBaseClassElements.put( element.getPropertyName(), element );
      }
    }

    //embeddable elements can have type defs
    bindTypeDefs( returnedClassOrElement, mappings );
    PropertyContainer propContainer = new PropertyContainer( returnedClassOrElement, xClassProcessed );
    addElementsOfClass( classElements, propertyAccessor, propContainer, mappings );

    //add elements of the embeddable superclass
    XClass superClass = xClassProcessed.getSuperclass();
    while ( superClass != null && superClass.isAnnotationPresent( MappedSuperclass.class ) ) {
      //FIXME: proper support of typevariables incl var resolved at upper levels
      propContainer = new PropertyContainer( superClass, xClassProcessed );
      addElementsOfClass( classElements, propertyAccessor, propContainer, mappings );
      superClass = superClass.getSuperclass();
    }
    if ( baseClassElements != null ) {
      //useful to avoid breaking pre JPA 2 mappings
      if ( !hasAnnotationsOnIdClass( xClassProcessed ) ) {
        for ( int i = 0; i < classElements.size(); i++ ) {
          final PropertyData idClassPropertyData = classElements.get( i );
          final PropertyData entityPropertyData = orderedBaseClassElements.get( idClassPropertyData.getPropertyName() );
          if ( propertyHolder.isInIdClass() ) {
            if ( entityPropertyData == null ) {
              throw new AnnotationException(
                  "Property of @IdClass not found in entity "
                      + baseInferredData.getPropertyClass().getName() + ": "
                      + idClassPropertyData.getPropertyName()
              );
            }
            final boolean hasXToOneAnnotation = entityPropertyData.getProperty()
                .isAnnotationPresent( ManyToOne.class )
                || entityPropertyData.getProperty().isAnnotationPresent( OneToOne.class );
            final boolean isOfDifferentType = !entityPropertyData.getClassOrElement()
                .equals( idClassPropertyData.getClassOrElement() );
            if ( hasXToOneAnnotation && isOfDifferentType ) {
              //don't replace here as we need to use the actual original return type
              //the annotation overriding will be dealt with by a mechanism similar to @MapsId
            }
            else {
              classElements.set( i, entityPropertyData )//this works since they are in the same order
            }
          }
          else {
            classElements.set( i, entityPropertyData )//this works since they are in the same order
          }
        }
      }
    }
    for ( PropertyData propertyAnnotatedElement : classElements ) {
      processElementAnnotations(
          subHolder, isNullable ?
              Nullability.NO_CONSTRAINT :
              Nullability.FORCED_NOT_NULL,
          propertyAnnotatedElement,
          new HashMap<String, IdGenerator>(), entityBinder, isIdentifierMapper, isComponentEmbedded,
          inSecondPass, mappings, inheritanceStatePerClass
      );

      XProperty property = propertyAnnotatedElement.getProperty();
      if ( property.isAnnotationPresent( GeneratedValue.class ) &&
          property.isAnnotationPresent( Id.class ) ) {
        //clone classGenerator and override with local values
        Map<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
        localGenerators.putAll( buildLocalGenerators( property, mappings ) );

        GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
        String generatorType = generatedValue != null ? generatorType(
            generatedValue.strategy(), mappings
        ) : "assigned";
        String generator = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT;

        BinderHelper.makeIdGenerator(
            ( SimpleValue ) comp.getProperty( property.getName() ).getValue(),
            generatorType,
            generator,
            mappings,
            localGenerators
        );
View Full Code Here

      PropertyHolder propertyHolder,
      PropertyData inferredData,
      boolean isComponentEmbedded,
      boolean isIdentifierMapper,
      Mappings mappings) {
    Component comp = new Component( mappings, propertyHolder.getPersistentClass() );
    comp.setEmbedded( isComponentEmbedded );
    //yuk
    comp.setTable( propertyHolder.getTable() );
    //FIXME shouldn't identifier mapper use getClassOrElementName? Need to be checked.
    if ( isIdentifierMapper || ( isComponentEmbedded && inferredData.getPropertyName() == null ) ) {
      comp.setComponentClassName( comp.getOwner().getClassName() );
    }
    else {
      comp.setComponentClassName( inferredData.getClassOrElementName() );
    }
    comp.setNodeName( inferredData.getPropertyName() );
    return comp;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Component$ValueGenerationPlan

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.