Unable to get the default Bean Validation factory
前几天看了一下教程 ,自己试着配置了一下web下的hibernate,悲剧的时,出错了提示下面:
信息: Hibernate Validator bean-validator-3.0-JBoss-4.0.2Exception in thread "main" org.hibernate.HibernateException: Unable to get the default Bean Validation factoryat org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:127)at org.hibernate.cfg.Configuration.applyBeanValidationConstraintsOnDDL(Configuration.java:1704)at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1654)at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1445)at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)at hb.sh.model.mainClass.main(mainClass.java:9)Caused by: java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:118)... 5 moreCaused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactoryat org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:383)at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:109)... 10 moreCaused by: javax.validation.ValidationException: Unable to instantiate Configuration.at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:272)at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:380)... 11 moreCaused by: java.lang.NullPointerExceptionat java.util.ResourceBundle.getBundle(ResourceBundle.java:960)at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.loadBundle(ResourceBundleMessageInterpolator.java:202)at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.getFileBasedResourceBundle(ResourceBundleMessageInterpolator.java:182)at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:81)at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:73)at org.hibernate.validator.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:57)at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:43)at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)... 13 more
在网上奔波了几天,都没打找到解决的办法,无奈啊,自己硬着头皮,看hibernate的帮助文档,搜索validation,打开有道词典边翻译边看帮助文档,希望它能帮我,功夫不负有心人,终于让我找到了一段:
- 23.1.1. Adding Bean Validation
- To enable Hibernate's Bean Validation integration, simply add a Bean Validation provider (preferably Hibernate Validation 4) on your classpath.
- 23.1.2. Configuration
- By default, no configuration is necessary.
- The Default group is validated on entity insert and update and the database model is updated accordingly based on the Default group as well.
- You can customize the Bean Validation integration by setting the validation mode. Use the javax.persistence.validation.mode property and set it up for example in your persistence.xml file or your hibernate.cfg.xml file. Several options are possible:
- auto (default): enable integration between Bean Validation and Hibernate (callback and ddl generation) only if Bean Validation is present in the classpath.
- none: disable all integration between Bean Validation and Hibernate
- callback: only validate entities when they are either inserted, updated or deleted. An exception is raised if no Bean Validation provider is present in the classpath.
- ddl: only apply constraints to the database schema when generated by Hibernate. An exception is raised if no Bean Validation provider is present in the classpath. This value is not defined by the Java Persistence spec and is specific to Hibernate.
- 注意
- You can use both callback and ddl together by setting the property to callback, dll
- <persistence ...>
- <persistence-unit ...>
- ...
- <properties>
- <property name="javax.persistence.validation.mode"
- value="callback, ddl"/>
- </properties>
- </persistence-unit>
- </persistence>
- This is equivalent to auto except that if no Bean Validation provider is present, an exception is raised.
- If you want to validate different groups during insertion, update and deletion, use:
- javax.persistence.validation.group.pre-persist: groups validated when an entity is about to be persisted (default to Default)
- javax.persistence.validation.group.pre-update: groups validated when an entity is about to be updated (default to Default)
- javax.persistence.validation.group.pre-remove: groups validated when an entity is about to be deleted (default to no group)
- org.hibernate.validator.group.ddl: groups considered when applying constraints on the database schema (default to Default)
- Each property accepts the fully qualified class names of the groups validated separated by a comma (,)
这里大意就是在hibernate.cfg.xml或者是persistence.xml文件下面需要配置javax.persistence.validation.mode属性
我不知道是什么意思,我于是直接改我的hibernate.cfg.xml文件里添加属性:
<property name="javax.persistence.validation.mode">none</property>
可怜的我居然hibernate居然不报错了。兴奋啊,javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包,但是找不到,所以beanvalitionFactory错误。
Unable to get the default Bean Validation factory的更多相关文章
- 使用hibernate时出现 org.hibernate.HibernateException: Unable to get the default Bean Validation factory
hibernate 在使用junit测试报错: org.hibernate.HibernateException: Unable to get the default Bean Validation ...
- juit测试中报错:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
org.hibernate.HibernateException: Unable to get the default Bean Validation factory 解决方法: 解决方案: 在hib ...
- Spring JUnit org.hibernate.HibernateException: Unable to get the default Bean Validation factory
org.hibernate.HibernateException: Unable to get the default Bean Validation factory <property nam ...
- org.hibernate.HibernateException: Unable to get the default Bean Validation factor
org.hibernate.HibernateException: Unable to get the default Bean Validation factor这个异常需要在hibernate.c ...
- spring和hibernate整合时报sessionFactory无法获取默认Bean Validation factory
Hibernate 3.6以上版本在用junit测试时会提示错误: Unable to get the default Bean Validation factory spring和hibernate ...
- Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testAction': ...
- javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
项目依赖 <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifa ...
- Exception in thread "main" javax.validation.ValidationException: Unable to find a default provider
Exception in thread "main" javax.validation.ValidationException: Unable to find a default ...
- Java数据校验(Bean Validation / JSR303)
文档: http://beanvalidation.org/1.1/spec/ API : http://docs.jboss.org/hibernate/beanvalidation/spec/1. ...
随机推荐
- centos自带的dvd中的官方base源,丢失了可以复制下面的内容
/etc/yum.repos.d/CentOS-Base.repo文件中的内容,同样适用于centos6 [base]name=CentOS-$releasever - Basemirrorlist= ...
- FDD vs TDD
双工方式 FDD vs TDD 频分双工(FDD) 收发信各占用一个频率. 优点是收.发信号同时进行,时延小,技术成熟,缺点是设备成本高. 时分双工(TDD) 收发信使用同一个频率,但使用不同 ...
- Ps操作技巧(快捷键大全)
一.工具箱(多种工具共用一个快捷键的可同时按[Shift]加此快捷键选取) 矩形.椭圆选框工具 [M] 移动工具 [V] 套索.多边形套索.磁性套索 [L] 魔棒工具 [W] 裁剪工具 [C] 切片工 ...
- 基于Linux的Samba开源共享解决方案测试(四)
对于客户端的网络监控如图: 双NAS网关100Mb码率视音频文件的稳定读测试结果如下: 100Mb/s负载性能记录 NAS网关资源占用 稳定写 稳定写 CPU空闲 内存空闲 网卡占用 NAS1 8个稳 ...
- Centos7下单机部署Solr7.3
本章重点介绍CentOS7 下部署Solr7 ,添加核心Core配置,Dataimport导入,中文分词的相关操作. 一.准备工作 演示环境是在虚拟机下安装的CentOS7.java JDK8 ...
- ajaxGet 获取封装
callback 表示下一个功能(回调函数) function ajaxGet(url,callback,data){ 如果路径上有参数 就在url后面拼接参数 否则只请求url ...
- FBV和CBV区别
FBV和CBV区别 def dispatch(self, request, *args, **kwargs): # 做分发的 if request.meth ...
- selenium+python自动化86-Chrome正在受到自动软件的控制
出现问题 1.用selenium启动浏览器出现'Chrome正在受到自动软件的控制' 2.如果不想看到这种讨厌的提示语,启动浏览器时候加个配置就行了 disable-infobars 1.在浏览器配置 ...
- 2018-2019-2 《网络对抗技术》Exp6 信息搜集与漏洞扫描 Week9 20165233
Exp6 信息搜集与漏洞扫描 目录 一.基础问题 二.实验步骤 实验点一:各种搜索技巧的应用 实验点二:DNS IP注册信息的查询 实验点三:基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具 ...
- cookie和session的比较
cookie和session的比较 一.对于cookie: ①cookie是创建于服务器端 ②cookie保存在浏览器端 ③cookie的生命周期可以通过cookie.setMaxAge(2000); ...