users@glassfish.java.net

Problems with Glassfish V3, Hibernate and log4j [SOLVED]

From: <glassfish_at_javadesktop.org>
Date: Thu, 11 Feb 2010 04:23:56 PST

Hi guys
We have started a new project based on the JEE6 stack on GF3, using Hibernate as persistence manager. We are having some weird problems trying to configure logging.

When we add a log4j.xml to the webapp, we get these errors:

log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.|#]
log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by |#]
log4j:ERROR [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)] whereas object of type |#]
log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)].|#]
log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator].|#]
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).|#]
log4j:WARN Please initialize the log4j system properly.|#]

Initially we thought this problem was because of incompatible versions of log4j, slf4j-log4j12, etc. but now we have tried all thinkable combinations. Another issue could be more than one log4.xml or log4j.properties in the webapp, but we have searched all dependencies and none of them contains log4j config.

We have stripped down everything in order to get a simple case to demonstrate the problem. These are the maven dependencies:

<dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>javaee-api</artifactId>
        <version>5.0-2</version>
        <scope>provided</scope>
</dependency>
<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.4.0.GA</version>
</dependency>
<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.4.2</version>
</dependency>
                
Which results in these jars in WEB-INF/lib:

antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
ejb3-persistence-1.0.2.GA.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-commons-annotations-3.1.0.GA.jar
hibernate-core-3.3.0.SP1.jar
hibernate-entitymanager-3.4.0.GA.jar
javassist-3.4.GA.jar
jta-1.1.jar
log4j-1.2.13.jar
slf4j-api-1.4.2.jar
slf4j-log4j12-1.4.2.jar
xml-apis-1.0.b2.jar

We have tried various different log4j.xml's, they all produce the same error. We have tried specifying <class-loader delegate="true"/> in sun-web.xml.

-----------------------------------

Update: Just as we were about to submit this, we tried putting log4j-1.2.13.jar in domains/domain1/lib, and voila.. Don't know if it makes sense to have it there but at least it works. Submitting this anyway in case other people get the same problem.
[Message sent by forum member 'andersaab' (andersaa_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=386092