spetrowitsch
asked on
Hibernate and JUnit-problem: LogConfigurationException
Hi,
I wanted to write a Testclass in JUnit with eclipse, which at first loads something out of my database with Hibernate.
But I get the following error:
java.lang.ExceptionInIniti alizerErro r
at hibernate.HibernateUtil.<c linit>(Hib ernateUtil .java:51)
at dao.BaseDAO.saveOrUpdateOb j(BaseDAO. java:34)
at dao.RechtsformDAO.saveOrUp date(Recht sformDAO.j ava:31)
at test.src.common.business.G egnerTest. setUp(Gegn erTest.jav a:86)
at junit.framework.TestCase.r unBare(Tes tCase.java :125)
at junit.framework.TestResult $1.protect (TestResul t.java:106 )
at junit.framework.TestResult .runProtec ted(TestRe sult.java: 124)
at junit.framework.TestResult .run(TestR esult.java :109)
at junit.framework.TestCase.r un(TestCas e.java:118 )
at junit.framework.TestSuite. runTest(Te stSuite.ja va:208)
at junit.framework.TestSuite. run(TestSu ite.java:2 03)
at junit.framework.TestSuite. runTest(Te stSuite.ja va:208)
at junit.framework.TestSuite. run(TestSu ite.java:2 03)
at junit.swingui.TestRunner$1 6.run(Test Runner.jav a:623)
Caused by: org.apache.commons.logging .LogConfig urationExc eption: org.apache.commons.logging .LogConfig urationExc eption: org.apache.commons.logging .LogConfig urationExc eption: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.loggin g.Log' visible, which is not allowed. (Caused by org.apache.commons.logging .LogConfig urationExc eption: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.loggin g.Log' visible, which is not allowed.) (Caused by org.apache.commons.logging .LogConfig urationExc eption: org.apache.commons.logging .LogConfig urationExc eption: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.loggin g.Log' visible, which is not allowed. (Caused by org.apache.commons.logging .LogConfig urationExc eption: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.loggin g.Log' visible, which is not allowed.))
at org.apache.commons.logging .impl.LogF actoryImpl .newInstan ce(LogFact oryImpl.ja va:543)
at org.apache.commons.logging .impl.LogF actoryImpl .getInstan ce(LogFact oryImpl.ja va:235)
at org.apache.commons.logging .impl.LogF actoryImpl .getInstan ce(LogFact oryImpl.ja va:209)
at org.apache.commons.logging .LogFactor y.getLog(L ogFactory. java:351)
at net.sf.hibernate.cfg.Confi guration.< clinit>(Co nfiguratio n.java:95)
... 14 more
Caused by: org.apache.commons.logging .LogConfig urationExc eption: org.apache.commons.logging .LogConfig urationExc eption: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.loggin g.Log' visible, which is not allowed. (Caused by org.apache.commons.logging .LogConfig urationExc eption: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.loggin g.Log' visible, which is not allowed.)
at org.apache.commons.logging .impl.LogF actoryImpl .getLogCon structor(L ogFactoryI mpl.java:3 97)
at org.apache.commons.logging .impl.LogF actoryImpl .newInstan ce(LogFact oryImpl.ja va:529)
... 18 more
Caused by: org.apache.commons.logging .LogConfig urationExc eption: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.loggin g.Log' visible, which is not allowed.
at org.apache.commons.logging .impl.LogF actoryImpl .getLogCon structor(L ogFactoryI mpl.java:3 85)
... 19 more
Does anyone know, which properties (and where) I have to change to get rid of that effect?
Thanks!!
I wanted to write a Testclass in JUnit with eclipse, which at first loads something out of my database with Hibernate.
But I get the following error:
java.lang.ExceptionInIniti
at hibernate.HibernateUtil.<c
at dao.BaseDAO.saveOrUpdateOb
at dao.RechtsformDAO.saveOrUp
at test.src.common.business.G
at junit.framework.TestCase.r
at junit.framework.TestResult
at junit.framework.TestResult
at junit.framework.TestResult
at junit.framework.TestCase.r
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.swingui.TestRunner$1
Caused by: org.apache.commons.logging
at org.apache.commons.logging
at org.apache.commons.logging
at org.apache.commons.logging
at org.apache.commons.logging
at net.sf.hibernate.cfg.Confi
... 14 more
Caused by: org.apache.commons.logging
at org.apache.commons.logging
at org.apache.commons.logging
... 18 more
Caused by: org.apache.commons.logging
at org.apache.commons.logging
... 19 more
Does anyone know, which properties (and where) I have to change to get rid of that effect?
Thanks!!
The jar file containing org.apache.commons.logging
ASKER
dejanpazin, I have that commons-loggin-1.0.4.jar
But when I remove it from my jars, I get another error:
java.lang.NoClassDefFoundE rror: org/apache/commons/logging /LogFactor y
at net.sf.hibernate.cfg.Confi guration.< clinit>(Co nfiguratio n.java:95)
at hibernate.HibernateUtil.<c linit>(Hib ernateUtil .java:51)
at src.common.businesstk.Vors atz.vorsat zSpeichern (Vorsatz.j ava:63)
at src.common.schnittstellen. tk.TkFaktP ureImport. addInfosat z(TkFaktPu reImport.j ava:83)
at test.src.common.schnittste llen.tk.Tk Schnittste lleFaktPur e.testAddI nfosatz(Tk Schnittste lleFaktPur e.java:135 )
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Na tiveMethod AccessorIm pl.java:39 )
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Delegati ngMethodAc cessorImpl .java:25)
at java.lang.reflect.Method.i nvoke(Meth od.java:58 5)
at junit.framework.TestCase.r unTest(Tes tCase.java :154)
at junit.framework.TestCase.r unBare(Tes tCase.java :127)
at junit.framework.TestResult $1.protect (TestResul t.java:106 )
at junit.framework.TestResult .runProtec ted(TestRe sult.java: 124)
at junit.framework.TestResult .run(TestR esult.java :109)
at junit.framework.TestCase.r un(TestCas e.java:118 )
at junit.framework.TestSuite. runTest(Te stSuite.ja va:208)
at junit.framework.TestSuite. run(TestSu ite.java:2 03)
at junit.framework.TestSuite. runTest(Te stSuite.ja va:208)
at junit.framework.TestSuite. run(TestSu ite.java:2 03)
at junit.swingui.TestRunner$1 6.run(Test Runner.jav a:623)
For me it seems, that I have to tell hibernate not to log at all - but I have no idea where...
But when I remove it from my jars, I get another error:
java.lang.NoClassDefFoundE
at net.sf.hibernate.cfg.Confi
at hibernate.HibernateUtil.<c
at src.common.businesstk.Vors
at src.common.schnittstellen.
at test.src.common.schnittste
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at junit.framework.TestCase.r
at junit.framework.TestCase.r
at junit.framework.TestResult
at junit.framework.TestResult
at junit.framework.TestResult
at junit.framework.TestCase.r
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.swingui.TestRunner$1
For me it seems, that I have to tell hibernate not to log at all - but I have no idea where...
From the exception it looks like you have org.apache.commons.logging
1. Check the classpath of your application and see all the jar files that it uses.
2. Search all those jars for org.apache.commons.logging
3. Dont remove commons-loggin-1.0.4.jar, cause you need that one, remove any other jars that contain org.apache.commons.logging
ASKER
Thanks, dejanpazin, I searched every jar-file, but there is still no other jar-file containing org.apache.commons.logging .Log-class
The only other idea I can think of is that you remove the org.apache.commons.logging
If the Log class really doesnt occur anywhere else, you should get error: java.lang.NoClassDefFoundE
ASKER
I removed the Log.class from the jar-file.
I get the message:
java.lang.ExceptionInIniti alizerErro r
at hibernate.HibernateUtil.<c linit>(Hib ernateUtil .java:51)
...
Caused by: org.apache.commons.logging .LogConfig urationExc eption: org.apache.commons.logging .LogConfig urationExc eption: java.lang.ClassNotFoundExc eption: org.apache.commons.logging .Log (Caused by java.lang.ClassNotFoundExc eption: org.apache.commons.logging .Log) (Caused by org.apache.commons.logging .LogConfig urationExc eption: java.lang.ClassNotFoundExc eption: org.apache.commons.logging .Log (Caused by java.lang.ClassNotFoundExc eption: org.apache.commons.logging .Log))
at org.apache.commons.logging .impl.LogF actoryImpl .newInstan ce(LogFact oryImpl.ja va:543)
at org.apache.commons.logging .impl.LogF actoryImpl .getInstan ce(LogFact oryImpl.ja va:235)
at org.apache.commons.logging .impl.LogF actoryImpl .getInstan ce(LogFact oryImpl.ja va:209)
at org.apache.commons.logging .LogFactor y.getLog(L ogFactory. java:351)
at net.sf.hibernate.cfg.Confi guration.< clinit>(Co nfiguratio n.java:95)
... 19 more
Line 51 in HibernateUtil is:
Configuration cfg = new Configuration();
I get the message:
java.lang.ExceptionInIniti
at hibernate.HibernateUtil.<c
...
Caused by: org.apache.commons.logging
at org.apache.commons.logging
at org.apache.commons.logging
at org.apache.commons.logging
at org.apache.commons.logging
at net.sf.hibernate.cfg.Confi
... 19 more
Line 51 in HibernateUtil is:
Configuration cfg = new Configuration();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@dejanpazin
Great, I see, that´s really the problem I encounter. I´ll see, whether I´m able to fix it...
Great, I see, that´s really the problem I encounter. I´ll see, whether I´m able to fix it...
ASKER
@dejanpazin
Now I know, where the error is - but I don´t know, how to solve it... I think, Hibernate and JUnit are both using the same logger, but in both cases I don´t use the class-loader, but it´s somewhere inside?!? So I don´t know, how to tell them to solve that parent-child-problem with ClassLoader...
Can you give me any hint?
Now I know, where the error is - but I don´t know, how to solve it... I think, Hibernate and JUnit are both using the same logger, but in both cases I don´t use the class-loader, but it´s somewhere inside?!? So I don´t know, how to tell them to solve that parent-child-problem with ClassLoader...
Can you give me any hint?
Hint is best I can do at this time. I'd try the following:
1. Try to see which classloader loads the classes first. Use
Thread.currentThread().get
I guess that would be in your case just before you call
Configuration cfg = new Configuration(); (its where the error occurs if you remove the Log class)
2. Set the same classloader at a place where error occurs (not the NoClassFound exception, but the exception of classloaders), use
Thread.currentThread().set
I belive this is where you have that:
GegnerTest.setUp()
You can try to call (before Configuration cfg = new Configuration()):
Thread.currentThread().set ContextCla ssLoader(C lassLoader .getSystem ClassLoade r());
If this doesn't work by itself then you can try also to put commons-loggin-1.0.4.jar
under your JVM (that one that is running eclipse) jre\lib\ext folder
Thread.currentThread().set
If this doesn't work by itself then you can try also to put commons-loggin-1.0.4.jar
under your JVM (that one that is running eclipse) jre\lib\ext folder
ASKER
@aozarov
Sorry, that doesn´t work.
Sorry, that doesn´t work.
Did you try them both (set context class loader as well as making sure that only one instance of commons-loggin exists and it is under jre\lib\ext)?
If so, do you get the same problem or do you get any other exception?
If so, do you get the same problem or do you get any other exception?
ASKER
It may sound unbelievable, but now I get the message:
(Could not find the main-class)
java.lang.NoClassDefFoundE rror: test/app/LexTest
Exception in thread "main"
(Could not find the main-class)
java.lang.NoClassDefFoundE
Exception in thread "main"
ASKER
I use not JUnit-module-Tests, not with GUI and TestSuites - and it works. Thanks to both of you!
You should check all the jar files that are used in your project.
There seem to be more than one jar file containing org.apache.commons.logging