问答详情
源自:3-1 显示学生资料——准备

JUnit4 测试问题的时候出现

TestStudent.testSchemaExport

testSchemaExport(entity.TestStudent)

org.hibernate.HibernateException: Error applying BeanValidation relational constraints


at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:219)


at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:126)


at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)


at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)


at entity.TestStudent.testSchemaExport(TestStudent.java:22)


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)


at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


at java.lang.reflect.Method.invoke(Method.java:601)


at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)


at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)


at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)


at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)


at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)


at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)


at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)


at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)


at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)


at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)


at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)


at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)


at org.junit.runners.ParentRunner.run(ParentRunner.java:236)


at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)


at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Caused by: java.lang.reflect.InvocationTargetException


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)


at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


at java.lang.reflect.Method.invoke(Method.java:601)


at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:208)


... 27 more


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


at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:524)


at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:119)


... 32 more


Caused 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:521)


... 33 more


Caused by: java.lang.NullPointerException


at java.util.ResourceBundle.getBundle(ResourceBundle.java:1026)


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)


... 35 more

TestStudent.testSaveStudent

testSaveStudent(entity.TestStudent)

org.hibernate.HibernateException: Error applying BeanValidation relational constraints


at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:219)


at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:126)


at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)


at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)


at entity.TestStudent.testSaveStudent(TestStudent.java:32)


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)


at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


at java.lang.reflect.Method.invoke(Method.java:601)


at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)


at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)


at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)


at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)


at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)


at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)


at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)


at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)


at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)


at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)


at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)


at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)


at org.junit.runners.ParentRunner.run(ParentRunner.java:236)


at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)


at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Caused by: java.lang.reflect.InvocationTargetException


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)


at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


at java.lang.reflect.Method.invoke(Method.java:601)


at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:208)


... 27 more


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


at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:524)


at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:119)


... 32 more


Caused 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:521)


... 33 more


Caused by: java.lang.NullPointerException


at java.util.ResourceBundle.getBundle(ResourceBundle.java:1026)


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)


... 35 more



就是说这句

 SessionFactory sessionFactory=config.buildSessionFactory(serviceRegistry);


提问者:TimzShiver 2017-03-14 22:02

个回答

  • 晤捂悟
    2017-04-09 12:54:06

    您好,你可以试试这个:

    在hibernate.hbm.xml中加上

    <property name="javax.persistence.validation.mode">none</property>

    希望能帮到你