[hibernate-issues] [Hibernate-JIRA] Created: (HV-344) Add example for configuring hibernate validator through Spring session factory bean

Roman Arkadijovych Muntyanu (JIRA) noreply at atlassian.com
Fri Jun 25 09:08:09 EDT 2010


Add example for configuring hibernate validator through Spring session factory bean
-----------------------------------------------------------------------------------

                 Key: HV-344
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-344
             Project: Hibernate Validator
          Issue Type: Improvement
          Components: documentation
    Affects Versions: 4.0.2.GA
            Reporter: Roman Arkadijovych Muntyanu
            Assignee: Hardy Ferentschik


Please add example for configuring hibernate validator through Spring session factory bean.
(!) It is *mandatory* to perform explicit validation framework configuration for it to start working, if hibernate configuration has been performed through Spring session factory.

The example may be like the following
{code:xml}
<!--Hibernate configuration properties for datasource-->
<bean id="hibernateConfigProperties"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <!--<property name="location" value="classpath:hibernate.properties"/>-->
    <property name="locations">
        <list>
            <value>classpath:hibernate.properties</value>
            <!--suppress SpringModelInspection -->
            <!--<value>classpath:compass.properties</value>-->
        </list>
    </property>
    <property name="properties">
        <props>
            <prop key="hibernate.dialect">${database.hibernate.dialect}</prop>
            <prop key="javax.persistence.validation.group.pre-persist">javax.validation.groups.Default</prop>
            <prop key="javax.persistence.validation.group.pre-update">javax.validation.groups.Default</prop>
        </props>
    </property>
</bean>

<!--  The session factory with all mappings -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingResources">
        <list>
            <value>org.hibernate.example.TestDTO.hbm.xml</value>
            ...
        </list>
    </property>
    <property name="hibernateProperties" ref="hibernateConfigProperties"/>
    <!-- Data source may be defined elsewhere-->
    <property name="dataSource" ref="dataSource"/> 
    <!-- This is how event-listeners are configured. 
         It is important that references to actual objects are passed. -->
    <property name="eventListeners">
        <map>
            <entry key="pre-update" value-ref="beanValidationEventListener"/>
            <entry key="pre-insert" value-ref="beanValidationEventListener"/>
        </map>
    </property>
</bean>

<!-- Define bean validation event listener -->
<bean id="beanValidationEventListener" class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/>
{code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list