Example usage for javax.persistence.metamodel EntityType getPluralAttributes

List of usage examples for javax.persistence.metamodel EntityType getPluralAttributes

Introduction

In this page you can find the example usage for javax.persistence.metamodel EntityType getPluralAttributes.

Prototype

Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes();

Source Link

Document

Return all multi-valued attributes (Collection-, Set-, List-, and Map-valued attributes) of the managed type.

Usage

From source file:ru.savvy.jpafilterbuilder.FilterCriteriaBuilder.java

/**
 * This clumsy code is just to get the class of plural attribute mapping
 *
 * @param et//from  w  ww  .  j a v a 2 s . c om
 * @param fieldName
 * @return
 */
private Class<?> getPluralJavaType(EntityType<?> et, String fieldName) {
    for (PluralAttribute pa : et.getPluralAttributes()) {
        if (pa.getName().equals(fieldName)) {
            switch (pa.getCollectionType()) {
            case COLLECTION:
                return et.getCollection(fieldName).getElementType().getJavaType();
            case LIST:
                return et.getList(fieldName).getElementType().getJavaType();
            case SET:
                return et.getSet(fieldName).getElementType().getJavaType();
            case MAP:
                throw new UnsupportedOperationException("Entity Map mapping unsupported for entity: "
                        + et.getName() + " field name: " + fieldName);
            }
        }
    }
    throw new IllegalArgumentException(
            "Field " + fieldName + " of entity " + et.getName() + " is not a plural attribute");
}