Example usage for org.hibernate.type ManyToOneType getReturnedClass

List of usage examples for org.hibernate.type ManyToOneType getReturnedClass

Introduction

In this page you can find the example usage for org.hibernate.type ManyToOneType getReturnedClass.

Prototype

@Override
public final Class getReturnedClass() 

Source Link

Document

This returns the wrong class for an entity with a proxy, or for a named entity.

Usage

From source file:org.nextframework.persistence.PersistenceUtils.java

License:Apache License

@SuppressWarnings("unchecked")
private static InverseCollectionProperties getInverseCollectionProperties(
        SessionFactoryImplementor sessionFactoryImplementor, Class<? extends Object> clazz,
        Class<?> returnedClass, String[] keyColumnNames, String[] propertyColumnNames, Type propertyType,
        String propertyName) {//from w  w w .  j a  v  a  2  s  .  c  o m
    if (propertyType instanceof ManyToOneType) {
        ManyToOneType mtot = (ManyToOneType) propertyType;
        if (mtot.getReturnedClass().isAssignableFrom(clazz)) {
            //if propertyColumnNames == keyColumnNames
            if (Arrays.deepEquals(propertyColumnNames, keyColumnNames)) {
                InverseCollectionProperties inverseCollectionProperties = new InverseCollectionProperties();
                inverseCollectionProperties.property = propertyName;
                inverseCollectionProperties.type = returnedClass;
                return inverseCollectionProperties;
            }
        }
    }
    if (propertyType instanceof ComponentType) {
        ComponentType ct = (ComponentType) propertyType;
        String[] propertyNames = ct.getPropertyNames();
        Type[] propertyTypes = ct.getSubtypes();
        int beginIndex = 0;
        for (int i = 0; i < propertyTypes.length; i++) {
            Type subType = propertyTypes[i];
            String subPropertyName = propertyNames[i];
            int columnSpan = subType.getColumnSpan(sessionFactoryImplementor);
            String[] propertyColumnNamesMapping = new String[columnSpan];
            System.arraycopy(propertyColumnNames, beginIndex, propertyColumnNamesMapping, 0, columnSpan);
            InverseCollectionProperties inverseCollectionProperties = getInverseCollectionProperties(
                    sessionFactoryImplementor, clazz, returnedClass, keyColumnNames, propertyColumnNamesMapping,
                    subType, subPropertyName);
            if (inverseCollectionProperties != null) {
                inverseCollectionProperties.property = propertyName + "."
                        + inverseCollectionProperties.property;
                return inverseCollectionProperties;
            }
            beginIndex += columnSpan;
        }
    }
    return null;
}