Announcement Announcement Module
Collapse
No announcement yet.
JSR-303 Field-level constraints would through error if no getter/setter available Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSR-303 Field-level constraints would through error if no getter/setter available

    Code:
    @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;
    	}        
    }
    The above code will cause the spring to through error

    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

    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.
    However spring forces me to have a getter/setter.

    Field level constraints and property level constraints are different and should be treated differently
    Last edited by ___; May 2nd, 2010, 01:00 PM.

  • #2
    Created a bug here http://jira.springframework.org/browse/SPR-7157

    Comment

    Working...
    X