コードをテストするために jUnit テストを作成します。オブジェクトをインスタンス化しようとすると、このエラーが発生します
java.lang.IllegalAccessError: tried to access method org.hibernate.cfg.Configuration.<init>(Lorg/hibernate/cfg/SettingsFactory;)V from class org.hibernate.ejb.Ejb3Configuration
at org.hibernate.ejb.Ejb3Configuration.<init>(Ejb3Configuration.java:134)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:124)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at gov.ic.isso.sentry.rest.data.CeReportDaoImpl.init(CeReportDaoImpl.java:41)
at gov.ic.isso.sentry.rest.data.DaoBase.<init>(DaoBase.java:20)
at gov.ic.isso.sentry.rest.data.CeReportDaoImpl.<init>(CeReportDaoImpl.java:33)
at gov.ic.isso.sentry.rest.AppTest.testApp(AppTest.java:41)
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 junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
私のinitメソッドのコードは
protected void init() {
emf = Persistence.createEntityManagerFactory("ceDataSessionData");
em = emf.createEntityManager();
}
私のjUnitテストは
public void testApp()
{
CeReportDao reportDao = new CeReportDaoImpl();
try {
reportDao.getMoneyTransferReportJson(100, "TESTUSER1", "NS", null);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}