Search in sources :

Example 6 with OneToMany

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;
}
Also used : OneToMany(org.hibernate.mapping.OneToMany) ManyToOne(org.hibernate.mapping.ManyToOne) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 7 with OneToMany

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);
    }
}
Also used : IndexBackref(org.hibernate.mapping.IndexBackref) OneToMany(org.hibernate.mapping.OneToMany) PluralAttributeElementSourceOneToMany(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceOneToMany) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

OneToMany (org.hibernate.mapping.OneToMany)7 ManyToOne (org.hibernate.mapping.ManyToOne)4 Component (org.hibernate.mapping.Component)3 PersistentClass (org.hibernate.mapping.PersistentClass)3 SimpleValue (org.hibernate.mapping.SimpleValue)3 Value (org.hibernate.mapping.Value)3 AnnotationException (org.hibernate.AnnotationException)2 Collection (org.hibernate.mapping.Collection)2 DependantValue (org.hibernate.mapping.DependantValue)2 IndexBackref (org.hibernate.mapping.IndexBackref)2 List (org.hibernate.mapping.List)2 Map (org.hibernate.mapping.Map)2 ComponentType (org.hibernate.type.ComponentType)2 Member (java.lang.reflect.Member)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Iterator (java.util.Iterator)1 Random (java.util.Random)1 MapKeyJoinColumn (javax.persistence.MapKeyJoinColumn)1 Type (javax.persistence.metamodel.Type)1 AssertionFailure (org.hibernate.AssertionFailure)1