Of course, there is always a reflection of annotations. Suppose you have a typical JPA column definition:
@Basic(optional = true) @Column(name = "MY_COLUMN_NAME_DESC", nullable = true, length = 255) public String getDesc() { return desc; }
Then, checking the getter method returns the value of the column name (an example is adopted from here ):
Method method = ... //obtain entity object Annotation[] annotations = method.getDeclaredAnnotations(); for(Annotation annotation : annotations){ if(annotation instanceof Column){ Column myAnnotation = (Column) annotation; System.out.println("name: " + myAnnotation.name()); System.out.println("value: " + myAnnotation.value()); } }
The example assumes a method for accessing properties in a JPA entity, but nothing prevents you from moving it to the field level by applying reflection to the field.
topchef
source share