Java examples for java.lang.annotation:Enterprise Annotation
get Table Name from Annotation
import javax.persistence.Entity; import javax.persistence.Table; public class Main{ public static void main(String[] argv) throws Exception{ Class clazz = String.class; System.out.println(getTableName(clazz)); }/*w w w . java2 s.co m*/ public static String getTableName(Class<?> clazz) { Table ann = clazz.getAnnotation(Table.class); if (ann != null && !"".equals(ann.name())) { return ann.name(); } return getEntityName(clazz); } public static String getEntityName(Class<?> clazz) { Entity ann = clazz.getAnnotation(Entity.class); if (ann != null && !"".equals(ann.name())) { return ann.name(); } return clazz.getSimpleName(); } }