By means of a specialized binder, Dynject can extract information from JPA-style annotations. To enable this, it's enough to call once somewhere in your code the following:
Shell.registerBinder(new JPABinder());
The following annotations are interpreted:
Here's a small sample illustrating validation:
@Entity
public class TestJPA {
private String stringField;
private double dblField;
@Column(name="dblField", precision=7, scale=3)
public double getDblField() {
return dblField;
}
public void setDblField(double dblField) {
this.dblField = dblField;
}
@Column(name="stringField", length=10)
public String getStringField() {
return stringField;
}
public void setStringField(String stringField) {
this.stringField = stringField;
}
public static void main(String[] args) {
Shell.registerBinder(new JPABinder());
TestJPA bean = new TestJPA();
bean.stringField = "Hello World";
bean.dblField = 12345678;
ErrorMap errors = Shell.validate(bean);
System.out.println(errors);
// An error is printed for DblField, specifying that a MaxDigits
// constraint has failed, and another one is printed for StringField,
// specifying that a Length constraint has been violated.
}
}
Of course, you are free to combine JPA and Dynject annotations.