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>