前几天看了一下教程 ,自己试着配置了一下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,打开有道词典边翻译边看帮助文档,希望它能帮我,功夫不负有心人,终于让我找到了一段:

  1.  
    23.1.1. Adding Bean Validation
  2.  
     
  3.  
    To enable Hibernate's Bean Validation integration, simply add a Bean Validation provider (preferably Hibernate Validation 4) on your classpath.
  4.  
     
  5.  
    23.1.2. Configuration
  6.  
     
  7.  
    By default, no configuration is necessary.
  8.  
     
  9.  
    The Default group is validated on entity insert and update and the database model is updated accordingly based on the Default group as well.
  10.  
     
  11.  
    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:
  12.  
     
  13.  
    auto (default): enable integration between Bean Validation and Hibernate (callback and ddl generation) only if Bean Validation is present in the classpath.
  14.  
    none: disable all integration between Bean Validation and Hibernate
  15.  
    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.
  16.  
    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.
  17.  
    注意
  18.  
    You can use both callback and ddl together by setting the property to callback, dll
  19.  
     
  20.  
    <persistence ...>
  21.  
    <persistence-unit ...>
  22.  
    ...
  23.  
    <properties>
  24.  
    <property name="javax.persistence.validation.mode"
  25.  
    value="callback, ddl"/>
  26.  
    </properties>
  27.  
    </persistence-unit>
  28.  
    </persistence>
  29.  
    This is equivalent to auto except that if no Bean Validation provider is present, an exception is raised.
  30.  
    If you want to validate different groups during insertion, update and deletion, use:
  31.  
     
  32.  
    javax.persistence.validation.group.pre-persist: groups validated when an entity is about to be persisted (default to Default)
  33.  
    javax.persistence.validation.group.pre-update: groups validated when an entity is about to be updated (default to Default)
  34.  
    javax.persistence.validation.group.pre-remove: groups validated when an entity is about to be deleted (default to no group)
  35.  
    org.hibernate.validator.group.ddl: groups considered when applying constraints on the database schema (default to Default)
  36.  
    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的更多相关文章

  1. 使用hibernate时出现 org.hibernate.HibernateException: Unable to get the default Bean Validation factory

    hibernate 在使用junit测试报错: org.hibernate.HibernateException: Unable to get the default Bean Validation ...

  2. juit测试中报错:org.hibernate.HibernateException: Unable to get the default Bean Validation factory

    org.hibernate.HibernateException: Unable to get the default Bean Validation factory 解决方法: 解决方案: 在hib ...

  3. 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 ...

  4. org.hibernate.HibernateException: Unable to get the default Bean Validation factor

    org.hibernate.HibernateException: Unable to get the default Bean Validation factor这个异常需要在hibernate.c ...

  5. spring和hibernate整合时报sessionFactory无法获取默认Bean Validation factory

    Hibernate 3.6以上版本在用junit测试时会提示错误: Unable to get the default Bean Validation factory spring和hibernate ...

  6. Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testAction': ...

  7. 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 ...

  8. 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 ...

  9. Java数据校验(Bean Validation / JSR303)

    文档: http://beanvalidation.org/1.1/spec/ API : http://docs.jboss.org/hibernate/beanvalidation/spec/1. ...

随机推荐

  1. 1073 Scientific Notation (20 分)

    1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very la ...

  2. Linux rpc 编程最简单实例

    通过rpcgen的man手册看到此工具的作用是把RPC源程序编译成C语言源程序,从而轻松实现远程过程调用.1.下面的例子程序的作用是客户端程序(fedora Linux下)取中心服务器也是Linux上 ...

  3. JpGraph使用详解之中文乱码解决方法

    在前面的JpGraph使用详解这篇文章,已经对JpGraph的使用方法作了详细的交代,前面说好的,接下来解决中文乱码. JpGraph为什么会出现中文乱码 在JpGraph中默认是要把字符串转成utf ...

  4. SIP 认证方式

    SIP认证是继承了HTTP的认证方式.HTTP的认证方案主要有Basic Authentication Scheme和Digest Access Authentication Scheme两种.而Ba ...

  5. osx 安装redis

    brew install redis 想关文章 http://www.tuicool.com/articles/nM73Enr http://www.iteye.com/topic/1124400

  6. django框架ajax

    参考 博文https://www.cnblogs.com/yuanchenqi/articles/9070966.html Ajax 简单示例: file_put文件上传页面: <!DOCTYP ...

  7. NOIP考前复习-数制转换,数论模板与文件读写

    数制转换有两种题型,一般一题,分值1.5分. 题型一:R进制转十进制 解法就是:按权展开,但要注意各个位的权,最低位(最右边)的权是0次方,权值为1. 纯整数的情况: (11010110)2 = 1× ...

  8. 如何分析 WindowsDump:Dump 起源与初始设置

    https://www.qcloud.com/community/article/511817 转者注:让我感觉以前看蓝屏都白看了~~~原来蓝屏也可以分析具体原因. 适用场景:Windows 系列系统 ...

  9. [Python] 分段线性插值

    利用线性函数做插值 每一段的线性函数: #Program 0.6 Linear Interploation import numpy as np import matplotlib.pyplot as ...

  10. 搜集几个API接口

    新浪:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 返回数据:var remote_ip_info = {"ret ...