use of org.hibernate.mapping.OneToMany in project hibernate-orm by hibernate.
the class CollectionMetadataGenerator method getReferenceCollectionClass.
private PersistentClass getReferenceCollectionClass(Collection collectionValue) {
PersistentClass referencedClass = null;
if (collectionValue.getElement() instanceof OneToMany) {
final OneToMany oneToManyValue = (OneToMany) collectionValue.getElement();
referencedClass = oneToManyValue.getAssociatedClass();
} else if (collectionValue.getElement() instanceof ManyToOne) {
// Case for bi-directional relation with @JoinTable on the owning @ManyToOne side.
final ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement();
referencedClass = manyToOneValue.getMetadata().getEntityBinding(manyToOneValue.getReferencedEntityName());
}
return referencedClass;
}
use of org.hibernate.mapping.OneToMany in project hibernate-orm by hibernate.
the class ModelBinder method createIndexBackRef.
private void createIndexBackRef(MappingDocument mappingDocument, IndexedPluralAttributeSource pluralAttributeSource, IndexedCollection collectionBinding) {
if (collectionBinding.isOneToMany() && !collectionBinding.getKey().isNullable() && !collectionBinding.isInverse()) {
final String entityName = ((OneToMany) collectionBinding.getElement()).getReferencedEntityName();
final PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding(entityName);
final IndexBackref ib = new IndexBackref();
ib.setName('_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "IndexBackref");
ib.setUpdateable(false);
ib.setSelectable(false);
ib.setCollectionRole(collectionBinding.getRole());
ib.setEntityName(collectionBinding.getOwner().getEntityName());
ib.setValue(collectionBinding.getIndex());
referenced.addProperty(ib);
}
}
Aggregations