use of org.hibernate.cfg.annotations.TableBinder in project hibernate-orm by hibernate.
the class AnnotationBinder method bindJoinedTableAssociation.
// TODO move that to collection binder?
private static void bindJoinedTableAssociation(XProperty property, MetadataBuildingContext buildingContext, EntityBinder entityBinder, CollectionBinder collectionBinder, PropertyHolder propertyHolder, PropertyData inferredData, String mappedBy) {
TableBinder associationTableBinder = new TableBinder();
JoinColumn[] annJoins;
JoinColumn[] annInverseJoins;
JoinTable assocTable = propertyHolder.getJoinTable(property);
CollectionTable collectionTable = property.getAnnotation(CollectionTable.class);
if (assocTable != null || collectionTable != null) {
final String catalog;
final String schema;
final String tableName;
final UniqueConstraint[] uniqueConstraints;
final JoinColumn[] joins;
final JoinColumn[] inverseJoins;
final javax.persistence.Index[] jpaIndexes;
// JPA 2 has priority
if (collectionTable != null) {
catalog = collectionTable.catalog();
schema = collectionTable.schema();
tableName = collectionTable.name();
uniqueConstraints = collectionTable.uniqueConstraints();
joins = collectionTable.joinColumns();
inverseJoins = null;
jpaIndexes = collectionTable.indexes();
} else {
catalog = assocTable.catalog();
schema = assocTable.schema();
tableName = assocTable.name();
uniqueConstraints = assocTable.uniqueConstraints();
joins = assocTable.joinColumns();
inverseJoins = assocTable.inverseJoinColumns();
jpaIndexes = assocTable.indexes();
}
collectionBinder.setExplicitAssociationTable(true);
if (jpaIndexes != null && jpaIndexes.length > 0) {
associationTableBinder.setJpaIndex(jpaIndexes);
}
if (!BinderHelper.isEmptyAnnotationValue(schema)) {
associationTableBinder.setSchema(schema);
}
if (!BinderHelper.isEmptyAnnotationValue(catalog)) {
associationTableBinder.setCatalog(catalog);
}
if (!BinderHelper.isEmptyAnnotationValue(tableName)) {
associationTableBinder.setName(tableName);
}
associationTableBinder.setUniqueConstraints(uniqueConstraints);
associationTableBinder.setJpaIndex(jpaIndexes);
// set check constaint in the second pass
annJoins = joins.length == 0 ? null : joins;
annInverseJoins = inverseJoins == null || inverseJoins.length == 0 ? null : inverseJoins;
} else {
annJoins = null;
annInverseJoins = null;
}
Ejb3JoinColumn[] joinColumns = Ejb3JoinColumn.buildJoinTableJoinColumns(annJoins, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), mappedBy, buildingContext);
Ejb3JoinColumn[] inverseJoinColumns = Ejb3JoinColumn.buildJoinTableJoinColumns(annInverseJoins, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), mappedBy, buildingContext);
associationTableBinder.setBuildingContext(buildingContext);
collectionBinder.setTableBinder(associationTableBinder);
collectionBinder.setJoinColumns(joinColumns);
collectionBinder.setInverseJoinColumns(inverseJoinColumns);
}
Aggregations