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

时间:2022-09-23 14:45:06

hibernate 在使用junit测试报错:

org.hibernate.HibernateException: Unable to get the default Bean Validation factory
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:)
at org.hibernate.cfg.Configuration.applyBeanValidationConstraintsOnDDL(Configuration.java:)
at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:)
at cn.ustc.test.HibernateTest1.testInsert(HibernateTest1.java:)
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.junit.runners.model.FrameworkMethod$.runReflectiveCall(FrameworkMethod.java:)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:)
at org.junit.runners.ParentRunner$.run(ParentRunner.java:)
at org.junit.runners.ParentRunner$.schedule(ParentRunner.java:)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:)
at org.junit.runners.ParentRunner.access$(ParentRunner.java:)
at org.junit.runners.ParentRunner$.evaluate(ParentRunner.java:)
at org.junit.runners.ParentRunner.run(ParentRunner.java:)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:)
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.BeanValidationActivator.applyDDL(BeanValidationActivator.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

解决方案:

hibernate.cfg.xml中配置的时候  增加如下配置

<property name="javax.persistence.validation.mode">none</property>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- 配置会话工厂(hibernate核心对象,管理数据库连接池) -->
<session-factory>
<!-- 连接数据库 JDBC 四个基本连接参数 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///hibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">111</property> <property name="javax.persistence.validation.mode">none</property> <!-- 配置hibernate 使用 数据库方言 -->
<!-- 方言解决 不同数据库 之间区别 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- 其它属性 -->
<!-- 自动建表 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 在日志中输出SQL -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property> <!-- 事务默认操作 -->
<property name="hibernate.connection.autocommit">false</property> <!-- 配置c3p0 -->
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <!-- 加载hbm映射 -->
<mapping resource="cn/ustc/domain/Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>

javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包,但是找不到,所以beanvalitionFactory错误。

使用hibernate时出现 org.hibernate.HibernateException: Unable to get the default Bean Validation factory的更多相关文章

  1. juit测试中报错:org&period;hibernate&period;HibernateException&colon; Unable to get the default Bean Validation factory

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

  2. Spring JUnit org&period;hibernate&period;HibernateException&colon; Unable to get the default Bean Validation factory

    org.hibernate.HibernateException: Unable to get the default Bean Validation factory <property nam ...

  3. org&period;hibernate&period;HibernateException&colon; Unable to get the default Bean Validation factor

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

  4. Unable to get the default Bean Validation factory

    前几天看了一下教程 ,自己试着配置了一下web下的hibernate,悲剧的时,出错了提示下面: 信息: Hibernate Validator bean-validator-3.0-JBoss-4. ...

  5. Caused by&colon; org&period;hibernate&period;HibernateException&colon; Unable to build the default ValidatorFactory

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

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

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

  7. Error creating bean with name &&num;39&semi;sessionFactory&&num;39&semi; defined in class path resource &lbrack;applicationContext&period;xml&rsqb;&colon; Invocation of init method failed&semi; nested exception is org&period;hibernate&period;HibernateException&colon; Unable t

    spring与hibernate整合然后出现如下错误: org.springframework.beans.factory.BeanCreationException: Error creating ...

  8. Caused by&colon;org&period;hibernate&period;HibernateException&colon;Unable to make JDBC Connection

    1.错误描述 Caused by:org.hibernate.HibernateException:Unable to make JDBC Connection[jdbc\:mysql\://loca ...

  9. org&period;hibernate&period;HibernateException&colon; Unable to instantiate default tuplizer &lbrack;org&period;hibernate&period;tuple&period;entity&period;PojoEntityTuplizer&rsqb;

    使用Hibernate 插入List数据时出现了以下异常: SLF4J: The requested version 1.6 by your slf4j binding is not compatib ...

随机推荐

  1. 【About Queue】(待改)

    队列 队列满足FIFO规则,先进先出. C语言代码:(Segmentation fault你大爷(メ ゚皿゚)メ) #include<stdio.h> #include<stdlib ...

  2. C&num;使用Log4Net记录日志

    当你在开发程序的时候, 调试(debugging)和日志(logging)都是非常重要的工作.在应用中使用日志主要有三个目的 l  监视代码中的变量的变化情况,把数据周期性地记录到文件*其它应用进行 ...

  3. 什么是JAVAbean

    JavaBean 是一种JAVA语言写成的可重用组件.为写成JavaBean,类必须是具体的和公共的,并且具有无参数的构造器.JavaBean 通过提供符合一致性设计模式的公共方法将内部域暴露成员属性 ...

  4. spring-aop示例

    具体案例放在github上,主要是jar包在上面 https://github.com/guoyansi/spring-aop-example knights.xml <?xml version ...

  5. ubuntu netbeans compile ygopro client with google protobuf lib

    environment: ubuntu 16.04 netbeans 8.2 ygopro Fluorohydride with Irrlicht Game Engine 问题1: google pr ...

  6. Maven的常用命令

    转载:http://www.cnblogs.com/phoebus0501/archive/2011/05/10/2042511.html Maven库: http://repo2.maven.org ...

  7. 通过innerHTML简化脚本

    <!doctype html> <html lang="en"> <head>   <meta charset="UTF-8&q ...

  8. UVA 10622 - Perfect P-th Powers&lpar;数论&rpar;

    UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...

  9. 目标检测(五)YOLOv1&mdash&semi;You Only Look Once&colon;Unified&comma;Real-Time Object Detection

    之前的目标检测算法大都采用proposals+classifier的做法(proposal提供位置信息,分类器提供类别信息),虽然精度很高,但是速度比较慢,也可能无法进行end-to-end训练.而该 ...

  10. linux脚本文件执行的方法之间的区别

    sh/bash sh a.sh bash a.sh 都是打开一个subshell去读取.执行a.sh,而a.sh不需要有"执行权限",在subshell里运行的脚本里设置变量,不会 ...