get Entity Name from Annotation - Java java.lang.annotation

Java examples for java.lang.annotation:Enterprise Annotation

Description

get Entity Name from Annotation

Demo Code


import javax.persistence.Entity;
import javax.persistence.Table;

public class Main{

    public static String getEntityName(Class<?> clazz) {
        Entity ann = clazz.getAnnotation(Entity.class);
        if (ann != null && !"".equals(ann.name())) {
            return ann.name();
        }//w w w .  ja  v a2 s .com
        return clazz.getSimpleName();
    }
}

Related Tutorials