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?