Announcement Announcement Module
Collapse
No announcement yet.
LocalValidatorFactoryBean causing MVC Internal Server Error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LocalValidatorFactoryBean causing MVC Internal Server Error

    I am using JSR-303 bean validation in a Spring MVC project. Everything works fine when I have a JSR-303 provider on the classpath, and leave all other validation settings in their default modes. I'd like to use spring managed beans in my custom validators, so I have added the following config to the org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean declaration:

    Code:
    <property name="jpaPropertyMap">
    	<map>
    	   	<entry key="javax.persistence.validation.factory" value-ref="validator" />
            </map>
    </property>
    
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
    When this config is used, it seems like beans annotated with @Valid are still validated within MVC controllers, but instead of MVC then catching the validation failures and presenting them on the form, a HTTP 500 error is caused and I get the following stacktrace from tomcat:


    Code:
    javax.validation.ConstraintViolationException: Validation failed for classes [xxx.model.WebPage] during update time for groups [javax.validation.groups.Default, ]
    List of constraint violations:[
    	ConstraintViolationImpl{interpolatedMessage='may not be empty', propertyPath=title, rootBeanClass=class xxx.model.WebPage, messageTemplate='{org.hibernate.validator.constraints.NotEmpty.message}'}
    	ConstraintViolationImpl{interpolatedMessage='{SiteUnique.default}', propertyPath=urlAlias, rootBeanClass=class xxx.model.WebPage, messageTemplate='{SiteUnique.default}'}
    ]
    	org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:161)
    	org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:102)
    	org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)
    	org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:86)
    	org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    	org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
    	org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
    	org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    	org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
    	org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
    	org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
    	org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    	org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
    	xxx.model.constraints.SiteUniqueValidator.isValid(SiteUniqueValidator.java:97)
    	org.hibernate.validator.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:278)
    	org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:153)
    	org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:117)
    	org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:84)
    	org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:452)
    	org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:397)
    	org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:361)
    	org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:313)
    	org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:139)
    	org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:86)
    	org.springframework.validation.DataBinder.validate(DataBinder.java:711)
    	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:807)
    	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:359)
    	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
    	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	net.sf.ehcache.constructs.web.filter.CachingFilter.buildPage(CachingFilter.java:302)
    	net.sf.ehcache.constructs.web.filter.SimpleCachingHeadersPageCachingFilter.buildPage(SimpleCachingHeadersPageCachingFilter.java:120)
    	xxx.commons.filters.PageCachingFilter.buildPageInfo(PageCachingFilter.java:64)
    	net.sf.ehcache.constructs.web.filter.CachingFilter.doFilter(CachingFilter.java:216)
    	net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java:86)
    	org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:74)
    	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	xxx.commons.filters.HttpHeadFilter.doFilter(HttpHeadFilter.java:47)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
    	org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    	org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    	org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    	org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    	org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    	org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    	org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    	org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
    	org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    	org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    Does anyone have any idea of what's going on here?
Working...
X