Package org.hibernate.mapping

Examples of org.hibernate.mapping.RootClass


    this.isXToMany = xToMany;
  }

  private Property bind(Property prop) {
    if (isId) {
      final RootClass rootClass = ( RootClass ) holder.getPersistentClass();
      //if an xToMany, it as to be wrapped today.
      //FIXME this pose a problem as the PK is the class instead of the associated class which is not really compliant with the spec
      if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {
        Component identifier = (Component) rootClass.getIdentifier();
        if (identifier == null) {
          identifier = AnnotationBinder.createComponent( holder, new PropertyPreloadedData(null, null, null), true, false, mappings );
          rootClass.setIdentifier( identifier );
          identifier.setNullValue( "undefined" );
          rootClass.setEmbeddedIdentifier( true );
        }
        //FIXME is it good enough?
        identifier.addProperty( prop );
      }
      else {
        rootClass.setIdentifier( ( KeyValue ) getValue() );
        if (embedded) {
          rootClass.setEmbeddedIdentifier( true );
        }
        else {
          rootClass.setIdentifierProperty( prop );
          final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
              declaringClass,
              inheritanceStatePerClass,
              mappings
          );
          if (superclass != null) {
            superclass.setDeclaredIdentifierProperty(prop);
          }
          else {
            //we know the property is on the actual entity
            rootClass.setDeclaredIdentifierProperty( prop );
          }
        }
      }
    }
    else {
View Full Code Here


    }
    persistentClass.setDynamicInsert( dynamicInsert );
    persistentClass.setDynamicUpdate( dynamicUpdate );

    if ( persistentClass instanceof RootClass ) {
      RootClass rootClass = (RootClass) persistentClass;
      boolean mutable = true;
      //priority on @Immutable, then @Entity.mutable()
      if ( annotatedClass.isAnnotationPresent( Immutable.class ) ) {
        mutable = false;
      }
      else {
        org.hibernate.annotations.Entity entityAnn =
            annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class );
        if ( entityAnn != null ) {
          mutable = entityAnn.mutable();
        }
      }
      rootClass.setMutable( mutable );
      rootClass.setExplicitPolymorphism( isExplicitPolymorphism( polymorphismType ) );
      if ( StringHelper.isNotEmpty( where ) ) rootClass.setWhere( where );
      if ( cacheConcurrentStrategy != null ) {
        rootClass.setCacheConcurrencyStrategy( cacheConcurrentStrategy );
        rootClass.setCacheRegionName( cacheRegion );
        rootClass.setLazyPropertiesCacheable( cacheLazyProperty );
      }
      rootClass.setNaturalIdCacheRegionName( naturalIdCacheRegion );
      boolean forceDiscriminatorInSelects = forceDiscriminator == null
          ? mappings.forceDiscriminatorInSelectsByDefault()
          : forceDiscriminator;
      rootClass.setForceDiscriminator( forceDiscriminatorInSelects );
      if( insertableDiscriminator != null) {
        rootClass.setDiscriminatorInsertable( insertableDiscriminator );
      }
    }
    else {
            if (explicitHibernateEntityAnnotation) {
        LOG.entityAnnotationOnNonRoot(annotatedClass.getName());
View Full Code Here

        subclassAndSingleTableStrategy,
        idPropertiesIfIdClass
    );

    if ( !inheritanceState.hasParents() ) {
      final RootClass rootClass = ( RootClass ) persistentClass;
      mappings.addSecondPass( new CreateKeySecondPass( rootClass ) );
    }
    else {
      superEntity.addSubclass( ( Subclass ) persistentClass );
    }
View Full Code Here

  private static PersistentClass makePersistentClass(InheritanceState inheritanceState, PersistentClass superEntity) {
    //we now know what kind of persistent entity it is
    PersistentClass persistentClass;
    //create persistent class
    if ( !inheritanceState.hasParents() ) {
      persistentClass = new RootClass();
    }
    else if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) {
      persistentClass = new SingleTableSubclass( superEntity );
    }
    else if ( InheritanceType.JOINED.equals( inheritanceState.getType() ) ) {
View Full Code Here

        );
      }
      if ( traceEnabled ) {
        LOG.tracev( "{0} is a version property", inferredData.getPropertyName() );
      }
      RootClass rootClass = ( RootClass ) propertyHolder.getPersistentClass();
      propertyBinder.setColumns( columns );
      Property prop = propertyBinder.makePropertyValueAndBind();
      setVersionInformation( property, propertyBinder );
      rootClass.setVersion( prop );

      //If version is on a mapped superclass, update the mapping
      final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
          inferredData.getDeclaringClass(),
          inheritanceStatePerClass,
          mappings
      );
      if ( superclass != null ) {
        superclass.setDeclaredVersion( prop );
      }
      else {
        //we know the property is on the actual entity
        rootClass.setDeclaredVersion( prop );
      }

      SimpleValue simpleValue = ( SimpleValue ) prop.getValue();
      simpleValue.setNullValue( "undefined" );
      rootClass.setOptimisticLockMode( Versioning.OPTIMISTIC_LOCK_VERSION );
      if ( traceEnabled ) {
        LOG.tracev( "Version name: {0}, unsavedValue: {1}", rootClass.getVersion().getName(),
            ( (SimpleValue) rootClass.getVersion().getValue() ).getNullValue() );
      }
    }
    else {
      final boolean forcePersist = property.isAnnotationPresent( MapsId.class )
          || property.isAnnotationPresent( Id.class );
View Full Code Here

      throw new AnnotationException(
          "Unable to define/override @Id(s) on a subclass: "
              + propertyHolder.getEntityName()
      );
    }
    RootClass rootClass = ( RootClass ) persistentClass;
    String persistentClassName = rootClass.getClassName();
    SimpleValue id;
    final String propertyName = inferredData.getPropertyName();
    HashMap<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
    if ( isComposite ) {
      id = fillComponent(
          propertyHolder, inferredData, baseInferredData, propertyAccessor,
          false, entityBinder, isEmbedded, isIdentifierMapper, false, mappings, inheritanceStatePerClass
      );
      Component componentId = ( Component ) id;
      componentId.setKey( true );
      if ( rootClass.getIdentifier() != null ) {
        throw new AnnotationException( componentId.getComponentClassName() + " must not have @Id properties when used as an @EmbeddedId" );
      }
      if ( componentId.getPropertySpan() == 0 ) {
        throw new AnnotationException( componentId.getComponentClassName() + " has no persistent id property" );
      }
      //tuplizers
      XProperty property = inferredData.getProperty();
      setupComponentTuplizer( property, componentId );
    }
    else {
      //TODO I think this branch is never used. Remove.

      for ( Ejb3Column column : columns ) {
        column.forceNotNull(); //this is an id
      }
      SimpleValueBinder value = new SimpleValueBinder();
      value.setPropertyName( propertyName );
      value.setReturnedClassName( inferredData.getTypeName() );
      value.setColumns( columns );
      value.setPersistentClassName( persistentClassName );
      value.setMappings( mappings );
      value.setType( inferredData.getProperty(), inferredData.getClassOrElement(), persistentClassName );
      value.setAccessType( propertyAccessor );
      id = value.make();
    }
    rootClass.setIdentifier( id );
    BinderHelper.makeIdGenerator( id, generatorType, generatorName, mappings, localGenerators );
    if ( isEmbedded ) {
      rootClass.setEmbeddedIdentifier( inferredData.getPropertyClass() == null );
    }
    else {
      PropertyBinder binder = new PropertyBinder();
      binder.setName( propertyName );
      binder.setValue( id );
      binder.setAccessType( inferredData.getDefaultAccess() );
      binder.setProperty( inferredData.getProperty() );
      Property prop = binder.makeProperty();
      rootClass.setIdentifierProperty( prop );
      //if the id property is on a superclass, update the metamodel
      final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
          inferredData.getDeclaringClass(),
          inheritanceStatePerClass,
          mappings
      );
      if ( superclass != null ) {
        superclass.setDeclaredIdentifierProperty( prop );
      }
      else {
        //we know the property is on the actual entity
        rootClass.setDeclaredIdentifierProperty( prop );
      }
    }
  }
View Full Code Here

      }
      else if ( "typedef".equals( elementName ) ) {
        bindTypeDef( element, mappings );
      }
      else if ( "class".equals( elementName ) ) {
        RootClass rootclass = new RootClass();
        bindRootClass( element, rootclass, mappings, inheritedMetas );
        mappings.addClass( rootclass );
      }
      else if ( "subclass".equals( elementName ) ) {
        PersistentClass superModel = getSuperclass( mappings, element );
View Full Code Here

      }
      else if ( "typedef".equals( elementName ) ) {
        bindTypeDef( element, mappings );
      }
      else if ( "class".equals( elementName ) ) {
        RootClass rootclass = new RootClass();
        bindRootClass( element, rootclass, mappings, inheritedMetas );
        mappings.addClass( rootclass );
      }
      else if ( "subclass".equals( elementName ) ) {
        PersistentClass superModel = getSuperclass( mappings, element );
View Full Code Here

    setCacheConcurrencyStrategy( clazz, concurrencyStrategy, region, true );
  }

  void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String region, boolean includeLazy)
      throws MappingException {
    RootClass rootClass = getRootClassMapping( clazz );
    if ( rootClass == null ) {
      throw new MappingException( "Cannot cache an unknown entity: " + clazz );
    }
    rootClass.setCacheConcurrencyStrategy( concurrencyStrategy );
    rootClass.setCacheRegionName( region );
    rootClass.setLazyPropertiesCacheable( includeLazy );
  }
View Full Code Here

    this.isXToMany = xToMany;
  }

  private Property bind(Property prop) {
    if (isId) {
      final RootClass rootClass = ( RootClass ) holder.getPersistentClass();
      //if an xToMany, it as to be wrapped today.
      //FIXME this pose a problem as the PK is the class instead of the associated class which is not really compliant with the spec
      if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {
        Component identifier = (Component) rootClass.getIdentifier();
        if (identifier == null) {
          identifier = AnnotationBinder.createComponent( holder, new PropertyPreloadedData(null, null, null), true, false, mappings );
          rootClass.setIdentifier( identifier );
          identifier.setNullValue( "undefined" );
          rootClass.setEmbeddedIdentifier( true );
          rootClass.setIdentifierMapper( identifier );
        }
        //FIXME is it good enough?
        identifier.addProperty( prop );
      }
      else {
        rootClass.setIdentifier( ( KeyValue ) getValue() );
        if (embedded) {
          rootClass.setEmbeddedIdentifier( true );
        }
        else {
          rootClass.setIdentifierProperty( prop );
          final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
              declaringClass,
              inheritanceStatePerClass,
              mappings
          );
          if (superclass != null) {
            superclass.setDeclaredIdentifierProperty(prop);
          }
          else {
            //we know the property is on the actual entity
            rootClass.setDeclaredIdentifierProperty( prop );
          }
        }
      }
    }
    else {
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.RootClass

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.