[hibernate-issues] [Hibernate-JIRA] Created: (HV-236) Spring/Hibernate integration, and maven suggestions

Ken Egervari (JIRA) noreply at atlassian.com
Thu Sep 24 04:44:50 EDT 2009


Spring/Hibernate integration, and maven suggestions
---------------------------------------------------

                 Key: HV-236
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-236
             Project: Hibernate Validator
          Issue Type: Improvement
          Components: documentation
    Affects Versions: 4.0.0.CR1
         Environment: spring 3.0, hibernate 3.3.2, hibernate validator 4.0cr1
            Reporter: Ken Egervari


HI,

I think it would a good idea to include an integration section on the documentation - a subsection on hibernate, an another subsection with spring. I'm sure jpa would be another.

To set up a validation in spring, all one needs to do is this:

    <bean id="validationFactory" class="javax.validation.Validation"
          factory-method="buildDefaultValidatorFactory" />
    
    <bean id="beanValidationEventListener" class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener">
        <constructor-arg index="0" ref="validationFactory" />
        <constructor-arg index="1">
            <props/>
        </constructor-arg>
    </bean>

Now, I don't know what the second properties argument is for... sending it an empty properties seems to work. I guess if that is the ValidationMessages.properties file... then it already gets picked up in the person's resources directory.

Since Spring is finicky if you specify the actual types, I think sharing this bean configuration would help people get moving on their projects faster. Let's face it, someone new to the library who can't find this info on google will spend hours. Let's give them a hand. I spent time doing it - let's now not make that time in vain and share with easily with people in the main documentation.

To wire these beans into the sessionfactory in hibernate, this is all that needs to be done given the other bean definitions:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="eventListeners">
            <map>
                <entry key="pre-insert" value-ref="beanValidationEventListener" />
                <entry key="pre-update" value-ref="beanValidationEventListener" />
            </map>
        </property>
....

And then they can keep adding more properties for configuration properties, mappings and whatever else. This works.

I hope sections like this appear in the documentation because really I want to do is help people, and make sure they don't have to go through what I went through to figure this out. I'm in huge favour of keeping things in 1 spot and spoon-feeding people.

-- 
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