Search in sources :

Example 1 with SpecialOneToOneType

use of org.hibernate.type.SpecialOneToOneType in project hibernate-orm by hibernate.

the class AbstractPropertyMapping method getCommonType.

private Type getCommonType(MetadataImplementor metadata, EntityType entityType1, EntityType entityType2) {
    PersistentClass thisClass = metadata.getEntityBinding(entityType1.getAssociatedEntityName());
    PersistentClass otherClass = metadata.getEntityBinding(entityType2.getAssociatedEntityName());
    PersistentClass commonClass = getCommonPersistentClass(thisClass, otherClass);
    if (commonClass == null) {
        return null;
    }
    // Create a copy of the type but with the common class
    if (entityType1 instanceof ManyToOneType) {
        ManyToOneType t = (ManyToOneType) entityType1;
        return new ManyToOneType(t, commonClass.getEntityName());
    } else if (entityType1 instanceof SpecialOneToOneType) {
        SpecialOneToOneType t = (SpecialOneToOneType) entityType1;
        return new SpecialOneToOneType(t, commonClass.getEntityName());
    } else if (entityType1 instanceof OneToOneType) {
        OneToOneType t = (OneToOneType) entityType1;
        return new OneToOneType(t, commonClass.getEntityName());
    } else {
        throw new IllegalStateException("Unexpected entity type: " + entityType1);
    }
}
Also used : SpecialOneToOneType(org.hibernate.type.SpecialOneToOneType) ManyToOneType(org.hibernate.type.ManyToOneType) PersistentClass(org.hibernate.mapping.PersistentClass) OneToOneType(org.hibernate.type.OneToOneType) SpecialOneToOneType(org.hibernate.type.SpecialOneToOneType)

Aggregations

PersistentClass (org.hibernate.mapping.PersistentClass)1 ManyToOneType (org.hibernate.type.ManyToOneType)1 OneToOneType (org.hibernate.type.OneToOneType)1 SpecialOneToOneType (org.hibernate.type.SpecialOneToOneType)1