use of org.hibernate.mapping.Join in project hibernate-orm by hibernate.
the class AbstractJPAIndexTest method testSecondaryTableIndex.
@Test
public void testSecondaryTableIndex() {
PersistentClass entity = metadata().getEntityBinding(Car.class.getName());
Join join = (Join) entity.getJoinIterator().next();
Iterator<Index> itr = join.getTable().getIndexIterator();
assertTrue(itr.hasNext());
Index index = itr.next();
assertFalse(itr.hasNext());
assertTrue("index name is not generated", StringHelper.isNotEmpty(index.getName()));
assertEquals(2, index.getColumnSpan());
Iterator<Column> columnIterator = index.getColumnIterator();
Column column = columnIterator.next();
assertEquals("dealer_name", column.getName());
column = columnIterator.next();
assertEquals("rate", column.getName());
assertSame(join.getTable(), index.getTable());
}
use of org.hibernate.mapping.Join in project hibernate-orm by hibernate.
the class AuditMetadataGenerator method addJoins.
@SuppressWarnings({ "unchecked" })
private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, ClassAuditingData auditingData, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) {
final Iterator<Join> joins = pc.getJoinIterator();
while (joins.hasNext()) {
final Join join = joins.next();
final Element joinElement = entitiesJoins.get(entityName).get(join);
if (joinElement != null) {
addProperties(joinElement, join.getPropertyIterator(), currentMapper, auditingData, entityName, xmlMappingData, firstPass);
}
}
}
use of org.hibernate.mapping.Join in project hibernate-orm by hibernate.
the class OneToOneTest method testJoinColumnConfiguredInXml.
@Test
@TestForIssue(jiraKey = "HHH-4606")
public void testJoinColumnConfiguredInXml() {
PersistentClass pc = metadata().getEntityBinding(Son.class.getName());
Iterator iter = pc.getJoinIterator();
Table table = ((Join) iter.next()).getTable();
Iterator columnIter = table.getColumnIterator();
boolean fooFound = false;
boolean barFound = false;
while (columnIter.hasNext()) {
Column column = (Column) columnIter.next();
if (column.getName().equals("foo")) {
fooFound = true;
}
if (column.getName().equals("bar")) {
barFound = true;
}
}
assertTrue("The mapping defines join columns which could not be found in the metadata.", fooFound && barFound);
}
use of org.hibernate.mapping.Join in project hibernate-orm by hibernate.
the class EntityBinder method processComplementaryTableDefinitions.
public void processComplementaryTableDefinitions(org.hibernate.annotations.Table table) {
//comment and index are processed here
if (table == null)
return;
String appliedTable = table.appliesTo();
Iterator tables = persistentClass.getTableClosureIterator();
Table hibTable = null;
while (tables.hasNext()) {
Table pcTable = (Table) tables.next();
if (pcTable.getQuotedName().equals(appliedTable)) {
//we are in the correct table to find columns
hibTable = pcTable;
break;
}
hibTable = null;
}
if (hibTable == null) {
//maybe a join/secondary table
for (Join join : secondaryTables.values()) {
if (join.getTable().getQuotedName().equals(appliedTable)) {
hibTable = join.getTable();
break;
}
}
}
if (hibTable == null) {
throw new AnnotationException("@org.hibernate.annotations.Table references an unknown table: " + appliedTable);
}
if (!BinderHelper.isEmptyAnnotationValue(table.comment()))
hibTable.setComment(table.comment());
TableBinder.addIndexes(hibTable, table.indexes(), context);
}
use of org.hibernate.mapping.Join 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