The above code will cause the spring to through errorCode:@Entity public class User extends BaseEntity { @NotEmpty @Basic private String _email; //No java bean style getter setter public String getEmail() { return _email; } public void setEmail(String email) { _email = email; } }
Code:Invalid property '_email' of bean class [org.ramanandi.matri.domain.model.User]: Bean property '_email' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property '_email' of bean class [org.ramanandi.matri.domain.model.User]: Bean property '_email' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:674) at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:666) at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:96) at org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:103) at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:79) at org.springframework.validation.DataBinder.validate(DataBinder.java:692) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:797) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:349) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:169) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) ................ ...............
As per the specification, Field level constraint should not need java bean style getters/setters and should be accessed using field access strategy
However spring forces me to have a getter/setter.When using field level constraints field access strategy is used to access the value to be validated. This means the instance variable directly independed of the access type.
Field level constraints and property level constraints are different and should be treated differently


Reply With Quote