Link to home
Start Free TrialLog in
Avatar of amirmb
amirmb

asked on

connection problem with derby when I want to insert new log messages into database

I have a java application and I use Spring, Hibernate and embedded Derby database.
As I wanted to save my log messages into database, I defined a new Appender for log4j. When in the appendar I want to read from database or write into it I get an exception that the root cause is :
Caused by: java.sql.SQLException: No current connection.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
I guess the problem is with the Embedded Derby and its limitation for just one connection and It seems that appender can't use the same connection in my application(probably because it runs in another thread or something) and it want to get a new one and can't.
Any idea to solve this problem without using the network derby?
Any suggestions?
Avatar of Mick Barry
Mick Barry
Flag of Australia image

derby can have more than one connection
your appender should open its own connection
Avatar of amirmb
amirmb

ASKER

Actually log4j JDBCAppender is not recommended from log4j guys. It has some problems I guess. And also I prefer to use hibernate rather than JDBC.
I'm not sure but I guess the embedded version of derby supports more than one connection just in the same JVM and same thread. I'm sure that you can't connect an embedded derby from different java applications. Maybe it has some issues with multi thread too. Maybe the problem is somewhere in hibernate. I'm not sure. If you have any experience about this problem, I will appreciate your help.
thats right, steer clear of that. And yes you can have more than one connectiion in the same vm, though the thread is irrelevant.
As I mentioned above your appender should be using its own connection, and not sharing the application one or you will have threading issues.
>>Actually log4j JDBCAppender is not recommended from log4j guys.

That's true, but log4j is itself superseded, so if you ARE worried about support and future-proofing, you should probably be using Logback and not writing your own db appender, but using their DBAppender:

http://logback.qos.ch/manual/appenders.html
ASKER CERTIFIED SOLUTION
Avatar of amirmb
amirmb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So it already is using it's own connection, you should be fine then.
Good to hear your problem is resolved.
Avatar of amirmb

ASKER

The problem was just a infinite loop. When you want to create a new logAppender, you should always be sure that your appender doesn't call any code that wants to log again. otherwise you'll face an infinite loop