Announcement Announcement Module
Collapse
No announcement yet.
Spring 3 + JBoss AS7 + Hibernate 4 - Validation using JSR-303 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3 + JBoss AS7 + Hibernate 4 - Validation using JSR-303

    Hi guys,


    I'm trying to get validation working with JSR-303 and it is just not working. I believe I have all the configuration in place (mvc:annotation-driven), the classes are using javax.persistance annotations. But my binder never show errors. No exceptions are thrown. No messages on the console. I'm using jboss and I belive hibernate validator is on the class path. It is on my pom.xml and the boot log shows this:

    00:03:39,468 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-3) Hibernate Validator 4.2.0.Final


    Any tips regarding what is the problem or at least how to debug it are super duper welcome. I wonder if I'm having some sort of conflict underneeth the hood.




    Here goes some code:

    Controller Method

    Code:
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    	public String create(@ModelAttribute @Valid MaterialEntry materialEntry,
    			BindingResult binder, Model model) {
    		if (binder.hasErrors()) {
    			System.out.println("Errors");
    		} else {
    			materialService.register(materialEntry);
    		}
    		return "redirect:/material/entries";
    	}
    POJO

    Code:
    @Entity
    @GenericGenerator(name = "materialEntryUuid", strategy = "uuid", parameters = { @Parameter(name = "uuid_gen_strategy_class", value = "org.hibernate.id.uuid.CustomVersionOneStrategy") })
    public class MaterialEntry {
    
    	@Id
    	@GeneratedValue(generator = "materialEntryUuid")
    	private String id;
    
    	@Temporal(TemporalType.TIMESTAMP)
    	@Column(nullable = false)
    	private Date timeStamp;
    
    	@NotNull(groups = { MaterialEntryDefaultGroup.class })
    	@Valid
    	@ManyToOne
    	@JoinColumn(name = "materialTypeId", nullable = false)
    	private MaterialType materialType;
    
    }
    web.xml

    Code:
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        metadata-complete="true">
    
        <display-name>Ekobin</display-name>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/META-INF/spring/applicationContext.xml,
    				classpath:/META-INF/spring/infrastructure.xml</param-value>
        </context-param>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <filter>
            <filter-name>openSessionInViewFilter</filter-name>
            <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
            <init-param>
                <param-name>entityManagerFactoryBeanName</param-name>
                <param-value>entityManagerFactory</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>openSessionInViewFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <servlet>
            <servlet-name>ekobin</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/jboss-as-spring-mvc-context.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>ekobin</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
        
    </web-app>
    aplicationContext.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee" xmlns:p="http://www.springframework.org/schema/p"
        xmlns:security="http://www.springframework.org/schema/security" xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    		http://www.springframework.org/schema/security
           	http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
    
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.user.repo" />
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.device.service" />
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.device.repo" />
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.material.service" />
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.material.repo" />
    
        <tx:jta-transaction-manager />
    
        <tx:annotation-driven />
    
    </beans>
    mvc.xml

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    
        <mvc:annotation-driven />
    
        <mvc:default-servlet-handler />
    
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.general.controller" />
    
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.device.controller" />
    
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.user.controller" />
    
        <context:component-scan base-package="br.com.ekoimpacto.ekobin.material.controller" />
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
        <mvc:resources mapping="/static/**" location="/WEB-INF/static/" />
    
    </beans>
    infrastructure.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/tx
    		   http://www.springframework.org/schema/tx/spring-tx.xsd
    		   http://www.springframework.org/schema/jee 
    		   http://www.springframework.org/schema/jee/spring-jee.xsd">
    
        <!-- JDNI name for EntityManagerFactory is defined in src/main/resources/META-INF/persistence.xml -->
        <jee:jndi-lookup jndi-name="java:jboss/ekobin/persistence" id="entityManagerFactory"
            expected-type="javax.persistence.EntityManagerFactory" />
        <jee:jndi-lookup jndi-name="java:jboss/datasources/MysqlDS" id="dataSource" expected-type="javax.sql.DataSource" />
    
        <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
    
        <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <property name="basenames">
                <list>
                    <value>classpath:messages/pageText</value>
                    <value>classpath:messages/general</value>
                </list>
            </property>
            <property name="defaultEncoding" value="UTF-8"></property>
            <property name="fallbackToSystemLocale" value="false" />
            <property name="cacheSeconds" value="3" />
            <property name="fileEncodings" value="UTF-8" />
        </bean>
    
        <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
            <property name="defaultLocale" value="pt_BR"></property>
        </bean>
    
        <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="lang" />
        </bean>
    
    </beans>
Working...
X