Search in sources :

Example 6 with DependantValue

use of org.hibernate.mapping.DependantValue in project hibernate-orm by hibernate.

the class EntityBinder method bindJoinToPersistentClass.

private void bindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns, MetadataBuildingContext buildingContext) {
    SimpleValue key = new DependantValue(buildingContext.getMetadataCollector(), join.getTable(), persistentClass.getIdentifier());
    join.setKey(key);
    setFKNameIfDefined(join);
    key.setCascadeDeleteEnabled(false);
    TableBinder.bindFk(persistentClass, null, ejb3JoinColumns, key, false, buildingContext);
    join.createPrimaryKey();
    join.createForeignKey();
    persistentClass.addJoin(join);
}
Also used : DependantValue(org.hibernate.mapping.DependantValue) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 7 with DependantValue

use of org.hibernate.mapping.DependantValue in project hibernate-orm by hibernate.

the class ValueVisitorTest method testProperCallbacks.

@Test
public void testProperCallbacks() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
    final Table tbl = new Table();
    final RootClass rootClass = new RootClass(metadataBuildingContext);
    ValueVisitor vv = new ValueVisitorValidator();
    new Any(metadata, tbl).accept(vv);
    new Array(metadata, rootClass).accept(vv);
    new Bag(metadata, rootClass).accept(vv);
    new Component(metadata, rootClass).accept(vv);
    new DependantValue(metadata, tbl, null).accept(vv);
    new IdentifierBag(metadata, rootClass).accept(vv);
    new List(metadata, rootClass).accept(vv);
    new ManyToOne(metadata, tbl).accept(vv);
    new Map(metadata, rootClass).accept(vv);
    new OneToMany(metadata, rootClass).accept(vv);
    new OneToOne(metadata, tbl, rootClass).accept(vv);
    new PrimitiveArray(metadata, rootClass).accept(vv);
    new Set(metadata, rootClass).accept(vv);
    new SimpleValue(metadata).accept(vv);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Set(org.hibernate.mapping.Set) ValueVisitor(org.hibernate.mapping.ValueVisitor) DependantValue(org.hibernate.mapping.DependantValue) MetadataSources(org.hibernate.boot.MetadataSources) Bag(org.hibernate.mapping.Bag) IdentifierBag(org.hibernate.mapping.IdentifierBag) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IdentifierBag(org.hibernate.mapping.IdentifierBag) OneToMany(org.hibernate.mapping.OneToMany) Any(org.hibernate.mapping.Any) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Array(org.hibernate.mapping.Array) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) OneToOne(org.hibernate.mapping.OneToOne) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) List(org.hibernate.mapping.List) Component(org.hibernate.mapping.Component) Map(org.hibernate.mapping.Map) Test(org.junit.Test)

Example 8 with DependantValue

use of org.hibernate.mapping.DependantValue in project hibernate-orm by hibernate.

the class ModelBinder method bindJoinedSubclassEntity.

private void bindJoinedSubclassEntity(JoinedSubclassEntitySourceImpl entitySource, JoinedSubclass entityDescriptor) {
    MappingDocument mappingDocument = entitySource.sourceMappingDocument();
    bindBasicEntityValues(mappingDocument, entitySource, entityDescriptor);
    final Table primaryTable = bindEntityTableSpecification(mappingDocument, entitySource.getPrimaryTable(), null, entitySource, entityDescriptor);
    entityDescriptor.setTable(primaryTable);
    if (log.isDebugEnabled()) {
        log.debugf("Mapping joined-subclass: %s -> %s", entityDescriptor.getEntityName(), primaryTable.getName());
    }
    // KEY
    final SimpleValue keyBinding = new DependantValue(mappingDocument.getMetadataCollector(), primaryTable, entityDescriptor.getIdentifier());
    if (mappingDocument.getBuildingOptions().useNationalizedCharacterData()) {
        keyBinding.makeNationalized();
    }
    entityDescriptor.setKey(keyBinding);
    keyBinding.setCascadeDeleteEnabled(entitySource.isCascadeDeleteEnabled());
    relationalObjectBinder.bindColumns(mappingDocument, entitySource.getPrimaryKeyColumnSources(), keyBinding, false, new RelationalObjectBinder.ColumnNamingDelegate() {

        int count = 0;

        @Override
        public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
            final Column column = primaryTable.getPrimaryKey().getColumn(count++);
            return database.toIdentifier(column.getQuotedName());
        }
    });
    keyBinding.setForeignKeyName(entitySource.getExplicitForeignKeyName());
    // model.getKey().setType( new Type( model.getIdentifier() ) );
    entityDescriptor.createPrimaryKey();
    entityDescriptor.createForeignKey();
    // todo : tooling hints
    bindAllEntityAttributes(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
    bindJoinedSubclassEntities(entitySource, entityDescriptor);
}
Also used : Table(org.hibernate.mapping.Table) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) Identifier(org.hibernate.boot.model.naming.Identifier) DependantValue(org.hibernate.mapping.DependantValue) Column(org.hibernate.mapping.Column) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 9 with DependantValue

use of org.hibernate.mapping.DependantValue in project hibernate-orm by hibernate.

the class OneToOneSecondPass method buildJoinFromMappedBySide.

/**
	 * Builds the <code>Join</code> instance for the mapped by side of a <i>OneToOne</i> association using 
	 * a join tables.
	 * <p>
	 * Note:<br/>
	 * <ul>
	 * <li>From the mappedBy side we should not create the PK nor the FK, this is handled from the other side.</li>
	 * <li>This method is a dirty dupe of EntityBinder.bindSecondaryTable</i>.
	 * </p>
	 */
private Join buildJoinFromMappedBySide(PersistentClass persistentClass, Property otherSideProperty, Join originalJoin) {
    Join join = new Join();
    join.setPersistentClass(persistentClass);
    //no check constraints available on joins
    join.setTable(originalJoin.getTable());
    join.setInverse(true);
    SimpleValue key = new DependantValue(buildingContext.getMetadataCollector(), join.getTable(), persistentClass.getIdentifier());
    //TODO support @ForeignKey
    join.setKey(key);
    join.setSequentialSelect(false);
    //TODO support for inverse and optional
    //perhaps not quite per-spec, but a Good Thing anyway
    join.setOptional(true);
    key.setCascadeDeleteEnabled(false);
    Iterator mappedByColumns = otherSideProperty.getValue().getColumnIterator();
    while (mappedByColumns.hasNext()) {
        Column column = (Column) mappedByColumns.next();
        Column copy = new Column();
        copy.setLength(column.getLength());
        copy.setScale(column.getScale());
        copy.setValue(key);
        copy.setName(column.getQuotedName());
        copy.setNullable(column.isNullable());
        copy.setPrecision(column.getPrecision());
        copy.setUnique(column.isUnique());
        copy.setSqlType(column.getSqlType());
        copy.setCheckConstraint(column.getCheckConstraint());
        copy.setComment(column.getComment());
        copy.setDefaultValue(column.getDefaultValue());
        key.addColumn(copy);
    }
    persistentClass.addJoin(join);
    return join;
}
Also used : DependantValue(org.hibernate.mapping.DependantValue) Column(org.hibernate.mapping.Column) Iterator(java.util.Iterator) Join(org.hibernate.mapping.Join) SimpleValue(org.hibernate.mapping.SimpleValue)

Aggregations

DependantValue (org.hibernate.mapping.DependantValue)9 SimpleValue (org.hibernate.mapping.SimpleValue)8 Column (org.hibernate.mapping.Column)5 Table (org.hibernate.mapping.Table)4 Iterator (java.util.Iterator)3 AnnotationException (org.hibernate.AnnotationException)3 Ejb3JoinColumn (org.hibernate.cfg.Ejb3JoinColumn)3 PersistentClass (org.hibernate.mapping.PersistentClass)3 CollectionTable (javax.persistence.CollectionTable)2 JoinTable (javax.persistence.JoinTable)2 AssertionFailure (org.hibernate.AssertionFailure)2 ForeignKey (org.hibernate.annotations.ForeignKey)2 Component (org.hibernate.mapping.Component)2 JoinedSubclass (org.hibernate.mapping.JoinedSubclass)2 ManyToOne (org.hibernate.mapping.ManyToOne)2 OneToMany (org.hibernate.mapping.OneToMany)2 Property (org.hibernate.mapping.Property)2 RootClass (org.hibernate.mapping.RootClass)2 ToOne (org.hibernate.mapping.ToOne)2 Value (org.hibernate.mapping.Value)2