Example usage for javax.persistence.metamodel EntityType getName

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

Introduction

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

Prototype

String getName();

Source Link

Document

Return the entity name.

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  .co  m
 * @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");
}