Junit - 由org.hibernate.AnnotationException引起的ExceptionInInitializerError

时间:2017-06-27 13:05:33

标签: java hibernate junit

当我尝试为我的班级运行Junit时出现此错误:

java.lang.ExceptionInInitializerError
    at xxx.yyy.zzz.dao.dashboard.TestDashboardDAO.setUp(TestDashboardDAO.java:36)
    at junit.framework.TestCase.runBare(TestCase.java:125)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
    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: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: xxx.yyy.zzz.bis.dashboard.details.dataDetails[xxx.yyy.zzz.bis.details.DataDetails]
    at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1168)
    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:693)
    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:628)
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
    at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1686)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1393)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1826)
    at xxx.yyy.zzz.dao.helper.TestSchema.<init>(TestSchema.java:62)
    ... 14 more

java.lang.ExceptionInInitializerError
    at xxx.yyy.zzz.dao.dashboard.TestDashboardDAO.setUp(TestDashboardDAO.java:36)
    at junit.framework.TestCase.runBare(TestCase.java:125)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
    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: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: xxx.yyy.zzz.bis.dashboard.details.dataDetails[xxx.yyy.zzz.bis.details.DataDetails]
    at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1168)
    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:693)
    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:628)
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
    at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1686)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1393)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1826)
    at xxx.yyy.zzz.dao.helper.TestSchema.<init>(TestSchema.java:62)
    ... 14 more

在setUp方法中,我只调用了初始化方法。哪个没被调用。 如何成功运行测试?

1 个答案:

答案 0 :(得分:0)

您需要在cfg xml文件中添加pojo映射。

<mapping class="xxx.yyy.zzz.bis.details.DataDetails" />

并确保在映射中指定DataDetails的相应限定名称。因为您的异常显示了两个不同的限定名称。