When spring and hibernate are integrated, sessionFactory cannot obtain the default Bean Validation factory and hibernatevalidation.

Source: Internet
Author: User

When spring and hibernate are integrated, sessionFactory cannot obtain the default Bean Validation factory and hibernatevalidation.

In Hibernate 3.6 or later versions, the following error occurs during junit testing: Unable to get the default Bean Validation factory.

When spring and hibernate are integrated, sessionFactory cannot obtain the default Bean Validation factory because the new version of hibernate uses a new jar package. By default, the verification package is automatically found. Wu does not need this step, you can add the following red attribute to the configuration node integrating spring and hibernate:

<Bean id = "sessionFactory" class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean">
<Property name = "dataSource" ref = "dataSource"> </property>
<Property name = "hibernateProperties">
<Props>
<Prop key = "hibernate. dialect"> org. hibernate. dialect. MySQL5Dialect </prop>
<Prop key = "hibernate. show_ SQL"> true </prop>
<Prop key = "hibernate. format_ SQL"> true </prop>
<Prop key = "hibernate. hbm2ddl. auto"> update </prop>
<Prop key = "hibernate. current_session_context_class"> thread </prop>
<Prop key = "javax. persistence. validation. mode"> none </prop>
</Props>
</Property>
<Property name = "mappingLocations" value = "classpath: cb/model/Custorm. hbm. xml"> </property>
</Bean>

The reason is: In Hibernate, the default <prop key = "javax. persistence. validation. mode"> none </prop> is auto rather than none!

Javax. persistence. validation. mode is auto by default, that is, if it is not set, it will automatically find a bean-validation.jar, but cannot be found, so the beanvalitionFactory error is reported.

If you want to use a verification package, you can add these jar packages

<dependency>        <groupId>javax.validation</groupId>        <artifactId>validation-api</artifactId>        <version>1.0.0.GA</version>    </dependency>    <dependency>        <groupId>org.hibernate</groupId>        <artifactId>hibernate-validator</artifactId>        <version>4.2.0</version>    </dependency>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.