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. ...
随机推荐
- 绕过限制,在PC上调试微信手机页面
场景 假设一个手机页面,开发者对其做了限制,导致只能在微信客户端中打开.而众所周知手机上非常不利于调试页面,所以需要能在电脑上打开并进行调试.这里针对常见的三种页面做一下分析,一一绕过其限制,(当然不 ...
- 最简单的TCP、UDP案例及各函数的详细解释
TCP: server #include "stdafx.h" #include<iostream> #define BUF_SZIE 64 #include &quo ...
- 面向服务的SOA架构与服务总线ESB
之前的软件的开发主要是面向对象的编程架构 方法---对象---模块---组件---服务,感觉现在的开发的主流的软件架构的设计思想都是对其进行重用,只不过范围越来越大,有一个系统之间进行通信到多个系统之 ...
- XPath 常用语法札记
* 不包含属性的元素 例如不包含属性的span: span[not(@*)] * 文本包含某部分的元素 例如文本包含Rank的元素: *[contains(text(),'Rank')] * 选择匹配 ...
- ORM PetaPoco 框架的 CRUD 操作
PetaPoco 的查询操作 public IEnumerable<T> GetAll(string sqlString, object[] obj) { try { IEnumerabl ...
- 并发基础(二) Thread类的API总结
Thread 类是java中的线程类,提供给用户用于创建.操作线程.获取线程的信息的类.是java线程一切的基础,掌握这个类是非常必须的,先来看一下它的API: 1.字段摘要 static int M ...
- Where is virtualenvwrapper.sh after pip install?
I'm trying to setup virtualenvwrapper on OSX, and all the instructions and tutorials I've found te ...
- JAVA SpringMVC + FormDate + Vue + file表单 ( 实现 js 单文件和多文件上传 )
JS 部分 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- leetcode953
public class Solution { public bool IsAlienSorted(string[] words, string order) { string HumanDic = ...
- java ee7 -- Java Bean验证
针对对象.对象成员.方法.构造函数的数据验证. 1. 一个验证的小例子 (1) 添加引用jar <dependency> <groupId>org.hibernate.vali ...