Example usage for org.hibernate.type EntityType isReferenceToPrimaryKey

List of usage examples for org.hibernate.type EntityType isReferenceToPrimaryKey

Introduction

In this page you can find the example usage for org.hibernate.type EntityType isReferenceToPrimaryKey.

Prototype

public boolean isReferenceToPrimaryKey() 

Source Link

Document

Does this association foreign key reference the primary key of the other table?

Usage

From source file:org.seasar.hibernate.jpa.metadata.HibernateAttributeDesc.java

License:Apache License

/**
 * <code>value</code>????<code>allValues</code>?????
 * //from   w  w  w  .  java 2s  .  c  om
 * @param allValues
 *            ??
 * @param type
 *            Hibernate?
 * @param value
 *            ????????
 */
protected void gatherAttributeValues(final List<Object> allValues, final Type type, final Object value) {

    if (value == null) {
        allValues.add(null);
        return;
    }
    if (!isReadTargetType(type)) {
        return;
    }

    if (type.isEntityType()) {
        final EntityType entityType = EntityType.class.cast(type);

        if (entityType.isReferenceToPrimaryKey()) {
            gatherIdAttributeValues(allValues, entityType, value);
        } else {
            final String name = entityType.getAssociatedEntityName();
            final EntityPersister ep = factory.getEntityPersister(name);
            final Type[] subtypes = ep.getPropertyTypes();
            final Object[] subvalue = ep.getPropertyValues(value, EntityMode.POJO);
            for (int i = 0; i < subtypes.length; i++) {
                gatherAttributeValues(allValues, subtypes[i], subvalue[i]);
            }
        }

    } else if (type.isComponentType()) {
        final AbstractComponentType componentType = AbstractComponentType.class.cast(type);
        final Object[] subvalues = componentType.getPropertyValues(value, EntityMode.POJO);
        final Type[] subtypes = componentType.getSubtypes();
        for (int i = 0; i < subtypes.length; i++) {
            gatherAttributeValues(allValues, subtypes[i], subvalues[i]);
        }

    } else {
        allValues.add(convert(type, value));
    }
}