I\'m working on an Spring application with lots of input forms. I\'d like to reuse the field length in the UI-form, validation and JPA annotations. Is there an elegant way t
The solution provided by EJB reads the annotated value for column length. James McMahon pointed out that this exposes the Hibernate implementation. That can be resolved fairly simply with getter methods. Assuming there is an interface for Person with a declared method getFirstNameLength:
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity
public class PersonImplementation extends Person {
@Column(length=30)
private String firstName;
public int getFirstNameLength() {
return this.getClass().getDeclaredField("firstName").getAnnotation(Column.class).length();
}
}