[英]Junit - ExceptionInInitializerError caused by org.hibernate.AnnotationException
I am getting this error when I try to run Junit for my class: 尝试为我的班级运行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
@OneToMany()
@LazyCollection(LazyCollectionOption.FALSE)
@JoinColumn(name="ID",referencedColumnName = "ID",insertable=false, updatable=false)
private List<DataDetails> dataDetails;
Inside the setUp method, I just called initializer method. 在setUp方法中,我只是调用了初始化方法。 Which was not invoked. 没有被调用。 What should I do to run the test successfully? 我应该怎么做才能成功运行测试?
You need to add pojo mapping in your cfg xml file. 您需要在cfg xml文件中添加pojo映射。
<mapping class="xxx.yyy.zzz.bis.details.DataDetails" />
and make sure you specify appropriate qualified name of DataDetails in mapping. 并确保在映射中指定适当的DataDetails合格名称。 because your exception shows two different qualified names. 因为您的例外显示两个不同的限定名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.