Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-17
8
Medium Priority
?
456 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:amirmb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34920150
derby can have more than one connection
your appender should open its own connection
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34920404
0
 

Author Comment

by:amirmb
ID: 34920741
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.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 92

Expert Comment

by:objects
ID: 34920813
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34921118
>>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
0
 

Accepted Solution

by:
amirmb earned 0 total points
ID: 34922114
Thank you for all your help. I found my problem. It was stupid actually. My appender was using the hibernate and DAOs to write into database and the service and DAO implementation wanted to generate new logs again. So it was kind of an infinite loop. And as it was transactional(I was using Spring services), the connections were passing the limit of connections before I get stackoverflow or heap exception.
Thanks again.
0
 
LVL 92

Expert Comment

by:objects
ID: 34922666
So it already is using it's own connection, you should be fine then.
Good to hear your problem is resolved.
0
 

Author Closing Comment

by:amirmb
ID: 35145558
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
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question