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);
}
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);
}
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);
}
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;
}
Aggregations