spring遇到的Error applying BeanValidation relational constraints
spring3.1+hibernate4集成测试时遇到的问题:
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
-- :: org.hibernate.validator.util.Version <clinit>
信息: Hibernate Validator bean-validator-3.0-JBoss-4.0.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Error applying BeanValidation relational constraints
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:)
at TestSpringHibernate.main(TestSpringHibernate.java:)
Caused by: org.hibernate.HibernateException: Error applying BeanValidation relational constraints
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:)
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
... more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:)
... more
Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:)
... more
Caused by: javax.validation.ValidationException: Unable to instantiate Configuration.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:)
... more
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle.getBundle(ResourceBundle.java:)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.loadBundle(ResourceBundleMessageInterpolator.java:)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.getFileBasedResourceBundle(ResourceBundleMessageInterpolator.java:)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:)
at org.hibernate.validator.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:)
... more
检查思路:
1、检查数据库是否开启;--已开启
2、检查表映射文件与实体类是否有问题。--没问题
3、检查配置文件applicationContext.xml
参考http://www.cnblogs.com/aipeli/articles/2537357.html
解决办法:
在使用Spring和Hibernate进行结合的时候出现了这个问题!
<prop key="javax.persistence.validation.mode">none</prop>
在配置文件中添加这个!
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="javax.persistence.validation.mode">none</prop>
</props>
</property>
其实这个问题是我们自己造成的!为什么这么说?因为我们在配置Spring和Hibernate进行结合的时候版本出现了问题。
<persistence ...>
<persistence-unit ...>
...
<properties>
<property name="javax.persistence.validation.mode"
value="callback, ddl"/>
</properties>
</persistence-unit>
</persistence>
这是hibernate官方文档的一段话意思就是在hibernate.cfg.xml或者是persistence.xml文件下面需要配置
javax.persistence.validation.mode属性!
特别的!在Hibernate中默认的 <prop key="javax.persistence.validation.mode">none</prop>
是auto而不是none!
引用:http://blog.163.com/guomaolin_gavin/blog/static/199618307201111197542905/
我的配置文件,applicationContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan">
<list>
<value>com.aipeli</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
<prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop>
<prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
<prop key="javax.persistence.validation.mode">none</prop>
</props>
</property>
</bean>
spring遇到的Error applying BeanValidation relational constraints的更多相关文章
- Error applying BeanValidation relational constraints 错误解决
来自http://blog.csdn.net/sivyer123/article/details/9185325 在hibernate.hbm.xml中加上 <property name=&qu ...
- Spring boot 处理 error 的套路
Spring boot 处理 error 的基本流程: Controller -> 发生错误 -> BasicErrorController -> 根据 @RequestMappin ...
- MongoDB在已有账号的实例下还原数据库报错的分析(error applying oplog)
一. 背景 今天在MongoDB 4.0.4版本下,在还原恢复数据库时报错. 主要错误为: Failed: restore error: error applying oplog: applyOps: ...
- spring boot session error
Error starting ApplicationContext. To display the conditions report re-run your application with 'de ...
- Spring Boot Web Error Page处理
spring Boot默认是whitelabel error page. 其实我们可以自己处理,由于时间有限,所以就简单说明一下方法. 首先配置 @Configuration public class ...
- spring boot :error querying database. Cause: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required
配置多个数据源启动报错,error querying database. Cause: java.lang.IllegalArgumentException: dataSource or dataSo ...
- Spring Boot : Whitelabel Error Page解决方案
楼主最近爱上了一个新框架--Spring Boot, 搭建快还不用写一堆xml,最重要的是自带Tomcat 真是好 pom.xml <?xml version="1.0" e ...
- Spring 整合WebSocket, Error during WebSocket handshake: Unexpected response code: 302 还有200的错误
springboot 集成websocket 及其简单,,,但是管理端使用的是Spring,原生配置,发生这个错误,,,302 被重定向了...我起的是本地locallhost,把ip换成 local ...
- Spring boot mybatis : Error creating bean with name 'com.github.pagehelper.autoconfigure.MapperAutoConfiguration': Invocation of init method failed;
报错截图: 解决方法: 只能扫描到自定义的mapper,不能扫描到其他文件. @MapperScan("com.streamax.s17.tms.dao.pper.repository&qu ...
随机推荐
- 软工团队 - UML设计
软工团队 - UML设计 分工 对于分工我们没有不是按"自己负责部分的核心模块做练习"(每个人对每个图的某一模块来依次做完四个UML)的原因,是在于画这些图并不是都能彻底分成各个& ...
- X的平方根的golang实现
实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 输入: 输出: 输入: 输出: 说明: 的 ...
- Windows Live Writer 2012在Blogjava管理和发布博客
下载Windows Live Writer 2012的完整版本(wlsetup-all.exe),安装的时候减少网络下载消耗的时间.注:有些平台可能还需要下载DotNet3.5(dotnetfx35. ...
- B - Moo Volume
Farmer John has received a noise complaint from his neighbor, Farmer Bob, stating that his cows are ...
- 连接rabbitmq
#消费者import pika # 连接服务器 credentials = pika.PlainCredentials('*****', '***') connection = pika.Blocki ...
- 为什么一定要学习linux系统?
为什么一定要学习linux系统? linux诞生了这么多年,以前还喊着如何能取代windows系统,现在这个口号已经小多了,任何事物发展都有其局限性都有其天花板.就如同在国内再搞一个社交软件取代腾讯一 ...
- UVA524-Prime Ring Problem(搜索剪枝)
Problem UVA524-Prime Ring Problem Accept:6782 Submit:43814 Time Limit: 3000 mSec Problem Descripti ...
- 转://SQLNET.EXPIRE_TIME参数
DCD: Dead Connection Detection ,可以用于检测.标记僵死而没有断开会session,再由PMON进行清理,释放资源.开启DCD,只需要在服务端的sqlnet.ora文件中 ...
- iptables 从一台机到另一台机端口转发
启用网卡转发功能#echo 1 > /proc/sys/net/ipv4/ip_forward 举例:从192.168.0.132:21521(新端口)访问192.168.0.211:1521端 ...
- A. Many Equal Substrings(水题)
思路: 直接比较橘色框里的取第一次相等,即可. #include<iostream> #include<string> using namespace std; string ...