Reputation: 1523
I create a jUnit test to test my code, when I try to instatiate my object, I get this error
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)
My code for my init method is
protected void init() {
emf = Persistence.createEntityManagerFactory("ceDataSessionData");
em = emf.createEntityManager();
}
My jUnit test is as
public void testApp()
{
CeReportDao reportDao = new CeReportDaoImpl();
try {
reportDao.getMoneyTransferReportJson(100, "TESTUSER1", "NS", null);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Upvotes: 4
Views: 3535
Reputation: 1523
Question has been answered by @Vikdor:
Appears to be incompatible hibernate jars in the classpath. Could you list the hibernate related jars along with their versions?
That was the issue. I had a dependency project which was pulling a old version of entitiy classes for hibernate and this project was pulling the latest and hence.
Upvotes: 0
Reputation: 71
I realize this is an old thread but I just thought I'd add one some extra info. I experienced this same problem with our Java 1.7
project using maven 3.3.3
.
Our integration tests using Spring 3.1.4
were working fine until I added a hibernate-annotations (ver. 3.5.4)
dependency to one of our artifacts. A downstream artifact then starting having the same IllegalAccessError
mentioned above.
After spending hours trying to discover the cause of the issue, I was able to fix it by changing the hibernate-annotations dependency that I had previously added to a hibernate-entitymanager
dependency. This fixed the downstream integration test problems.
My only point of mentioning this was to note that at no time did I have different versions of Hibernate jars on the classpath
. Maven was showing all hibernate versions as 3.5.4 with the exception of a few jars that are supposed to have different versions (e.g., hibernate-common-annotations 3.2.0
). So, I believe the comment above about having different Hibernate jars is not the issue in my case.
Upvotes: 1