log4j Causing Exceptions

25 views
Skip to first unread message

Rob Ogilvie

unread,
Jul 19, 2010, 12:23:55 PM7/19/10
to mybati...@googlegroups.com
Good Morning,

I'm attempting to implement log4j logging for MyBatis to troubleshoot my single-result collection being null issue.  I am getting exceptions (see bottom of this email) when I merely add log4j-1.2.16.jar to the classpath.  Even if I don't reference it, or drop a configuration or XML file anywhere.  If I all I do is add the jar file to the classpath and drop the XML file from the wiki and DTD from log4j, I get identical results.

Is this somehow caused by the GWT environment, or is it a MyBatis issue?  Any thoughts on how I might work around it?

Rob

The exceptions:
   [WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract project.shared.beans.AARBean
project.client.services.AARService.getAARFromServer(long) throws
java.lang.IllegalArgumentException' threw an unexpected exception:
java.lang.ExceptionInInitializerError
        at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
378)
        at
com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:
581)
        at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServi

ceServlet.java:
188)
        at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:
224)
        at
com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:
62)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
487)
        at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
362)
        at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
        at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
181)
        at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
729)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
405)
        at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
        at
org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:
49)
        at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
        at org.mortbay.jetty.Server.handle(Server.java:324)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
505)
        at org.mortbay.jetty.HttpConnection
$RequestHandler.content(HttpConnection.java:843)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
        at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
395)
        at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.ExceptionInInitializerError
        at
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:
44)
        at
project.server.data.ConnectionFactory.<init>(ConnectionFactory.java:
59)
        at
project.server.data.ConnectionFactory.getTheConnectionFactory(ConnectionFactory.java:
86)
        at project.server.data.AARDAO.<clinit>(AARDAO.java:13)
        at
project.handlers.AARServiceImpl.getAARFromServer(AARServiceImpl.java:
21)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at
com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:
562)
        ... 22 more
Caused by: org.apache.ibatis.logging.LogException: Error creating
logger for class interface java.sql.Connection.  Cause:
java.lang.reflect.InvocationTargetException
        at org.apache.ibatis.logging.LogFactory.getLog(LogFactory.java:43)
        at
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.<clinit>(DefaultSqlSessionFactory.java:
21)
        ... 32 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.apache.ibatis.logging.LogFactory.getLog(LogFactory.java:41)
        ... 33 more
Caused by: org.apache.commons.logging.LogConfigurationException:
org.apache.commons.logging.LogConfigurationException: No suitable Log
constructor [Ljava.lang.Class;@10f5104 for
org.apache.commons.logging.impl.Log4JLogger (Caused by
java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by
org.apache.commons.logging.LogConfigurationException: No suitable Log
constructor [Ljava.lang.Class;@10f5104 for
org.apache.commons.logging.impl.Log4JLogger (Caused by
java.lang.NoClassDefFoundError: org/apache/log4j/Category))
        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
org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl.<init>(JakartaCommonsLoggingImpl.java:
11)
        ... 38 more
Caused by: org.apache.commons.logging.LogConfigurationException: No
suitable Log constructor [Ljava.lang.Class;@10f5104 for
org.apache.commons.logging.impl.Log4JLogger (Caused by
java.lang.NoClassDefFoundError: org/apache/log4j/Category)
        at
org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:
413)
        at
org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:
529)
        ... 42 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Category
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
        at java.lang.Class.getConstructor0(Unknown Source)
        at java.lang.Class.getConstructor(Unknown Source)
        at
org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:
410)
        ... 43 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Category
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 48 more
[ERROR] 500 - POST /aar (127.0.0.1) 57 bytes
   Request headers
      Host: 127.0.0.1:8888
      User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:
1.9.2) Gecko/20100115 Firefox/3.6 ( .NET CLR 3.5.30729)
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
      Accept-Language: en-us,en;q=0.5
      Accept-Encoding: gzip,deflate
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
      Keep-Alive: 115
      Connection: keep-alive
      Referer: http://127.0.0.1:8888/project/hosted.html?project
      Cache-Control: no-cache
      X-GWT-Permutation: HostedMode
      X-GWT-Module-Base: http://127.0.0.1:8888/project/
      Content-Type: text/x-gwt-rpc; charset=utf-8
      Content-Length: 170
      Pragma: no-cache
   Response headers
      Content-Type: text/plain


Guy Rouillier

unread,
Jul 19, 2010, 4:27:25 PM7/19/10
to mybati...@googlegroups.com
You are getting this exception because you are trying to use MyBatis as
an SQL logger for your log4j output. Do you really want to do this? If
you are simply trying to debug your original issue, then this is adding
an unnecessary layer of complexity to your environment.

At any rate, take one problem at a time. Switch your log4j
configuration to use a simple ConsoleAppender. Debug your original
issue. Then, if you want to use a SQL logger in log4j, tackle that
issue with otherwise working code.

On 7/19/2010 12:23 PM, Rob Ogilvie wrote:
> Good Morning,
>
> I'm attempting to implement log4j logging for MyBatis to troubleshoot my
> single-result collection being null issue. I am getting exceptions (see

> bottom of this email) when I merely add log4j-1.2.16jar to the

> Host: 127.0.0.1:8888 <http://127.0.0.1:8888>


> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:
> 1.9.2) Gecko/20100115 Firefox/3.6 ( .NET CLR 3.5.30729)
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 115
> Connection: keep-alive

> Referer: http://127.0.01:8888/project/hosted.html?project
> <http://www.google.com/url?sa=D&q=http://127.0.0.1:8888/project/hosted.html%3Fproject&usg=AFQjCNFaPBQ00mVJHo5yYYI0qppXDHdCGA>


>
> Cache-Control: no-cache
> X-GWT-Permutation: HostedMode
> X-GWT-Module-Base: http://127.0.0.1:8888/project/

> <http://www.google.com/url?sa=D&q=http://127.0.0.1:8888/project/&usg=AFQjCNG_v2DcGGHXMi5E_HMLnhNJlEFXVw>


>
> Content-Type: text/x-gwt-rpc; charset=utf-8
> Content-Length: 170
> Pragma: no-cache
> Response headers
> Content-Type: text/plain
>
>


--
Guy Rouillier

Rob Ogilvie

unread,
Jul 19, 2010, 5:48:52 PM7/19/10
to mybati...@googlegroups.com
Guy,

Thank you for your assistance.  Before I read your message, I fumbled through getting MyBatis debugging and was able to see it returning rows, which lead my focus to other parts of my code.  A seemingly innocuous bit of code was handling null ArrayLists being passed in to the container object, recreating the ArrayList if it was null.  Unfortunately,  I typed a 1 instead of a 0 in a size parameter of the test which caused a resultset of size 1 to be recreated as a blank result.  Oops.  Ouch.

I am now on to my next issue, which should hopefully be a bit easier to debug, as it's only happening in Tomcat and not the GWT development mode.

Rob
Reply all
Reply to author
Forward
0 new messages