-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Hibernate and JUnit: LogConfigurationException
PostPosted: Tue May 10, 2005 6:34 am 
Newbie

Joined: Tue Apr 12, 2005 9:16 am
Posts: 3
Location: germany
I use Hibernate, and test my application with JUnit.
When I do the first database-command, I get a LogConfigurationException.

The command, where I get problems, is:

protected void saveOrUpdateObj(Object obj) throws DAOException
{
try {
Session session = HibernateUtil.getSession(); // Here I get the exception

HibernateUtil.beginTransaction();
session.saveOrUpdate(obj);
HibernateUtil.commitTransaction();
} catch (HibernateException he) {
throw new DAOException(he);
} finally {
HibernateUtil.closeSession();
}
}

At that point it calls the first time in my HibernateUtil-class:
static {
try {
Configuration cfg = cfg = new Configuration(); // Here I get
// the exception

sessionFactory = cfg.configure(CONFIG_FILE_LOCATION).buildSessionFactory();
} catch (Throwable ex) {
ex.printStackTrace(System.out);
throw new ExceptionInInitializerError(ex);
}
}

The stackTrace of the exception is:


java.lang.ExceptionInInitializerError
at hibernate.HibernateUtil.<clinit>(HibernateUtil.java:51)
at dao.BaseDAO.saveOrUpdateObj(BaseDAO.java:34)
at dao.RechtsformDAO.saveOrUpdate(RechtsformDAO.java:31)
at test.src.common.business.GegnerTest.setUp(GegnerTest.java:86)
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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.swingui.TestRunner$16.run(TestRunner.java:623)
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed. (Caused by org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.) (Caused by org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed. (Caused by org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.))
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at net.sf.hibernate.cfg.Configuration.<clinit>(Configuration.java:95)
... 14 more
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed. (Caused by org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
... 18 more
Caused by: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:385)
... 19 more


If I see that right, the cause is in the class loaders. The Log implementation is loaded through different classloader than the Log interface and are therefore considered different, which is why I get the exception. That is explained here: http://www.qos.ch/logging/classloader.jsp


Does anyone know, how to solve that problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 7:32 am 
Newbie

Joined: Tue Apr 12, 2005 9:16 am
Posts: 3
Location: germany
When I do the same without GUI and TestSuites, it works well...


Top
 Profile  
 
 Post subject: Hibernate and JUnit: LogConfigurationException
PostPosted: Wed Apr 26, 2006 8:25 am 
Newbie

Joined: Wed Apr 26, 2006 8:15 am
Posts: 2
Hi there I'm having the same problem. Did you find a solution?

Many thanks,
Max


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sat Jun 10, 2006 9:42 am 
Newbie

Joined: Sat Jun 10, 2006 9:35 am
Posts: 3
Try to use commons-logging-api-1.1.jar instead of commons-logging-1.1.jar.
I think it has been released (by apache) to solve also this problem.

Bye Loris

Don't forget the credit system ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 11:03 am 
Newbie

Joined: Sat Mar 18, 2006 1:13 am
Posts: 10
I'm guessing it's one of two things.

1.) You have multiple versions of commons-logging available. JUnit, hibernate and other 3rd party frameworks all have a tendency to deploy a version of commons-xxx.jar with their distro. As you create your application and its jars, prune things so there is only one. Check for jar inside of jar and that kind of thing. might also need to examine CLASSPATH and see if it has 2 such jars on it. Likewise, look in places like tomcat/common/lib, or your appserver shared-lib directory for extra copies.

2.) What are you using for logging? I assume Log4J. Do you specify the location of the log4j config file or do you let log4j figure it out itself? I've encountered probs when I let log4j guess, so I generally do a -Dlog4j.configuration=<path to config> when I launch. I believe the guessing algorithm goes hunting for a file "log4j.config", which it will frequently find inside of things like commons-xxx.jar. Whacky behavior may result because it is using the wrong configuration file. Be explicit.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 4:45 am 
Newbie

Joined: Wed Apr 26, 2006 8:15 am
Posts: 2
Hi Folks,
got this fixed. It's definitely to do with having multiple instances on the classpath. I got it down to one and it works fine.

Cheers,
Max


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.