-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: logging all prepared statement parameters to std out
PostPosted: Mon Jan 12, 2004 11:56 am 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
I have the log level set to debug in the log4j.properties and I have hibernate.show_sql = true in hibernate.properties but the output from hibernate is just showing the prepared statement. It doesn't show the actual values being set on the prepared statement parameters, when the statement fails!


Code:
[1/12/04 10:44:30:647 EST]  32a032a SystemOut     O Hibernate: insert into db2admin.CSTMR_GM_WN_AMNT_ODD (GM_WIN_AMOUNT_ODD, PRIZE_FOR_WIN_AMOUNT, PRIZE_FOR_WIN_AMNT_DESC, AUD_LSUP_TS, AUD_CREATE_TS, GAME_ID, GAME_WIN_AMOUNT_ID, CSTMR_GAME_ID) values (?, ?, ?, ?, ?, ?, ?, ?)

[1/12/04 10:44:30:847 EST]  32a032a JDBCException W net.sf.hibernate.util.JDBCExceptionReporter  SQL Error: -530, SQLState: 23503
[1/12/04 10:44:30:847 EST]  32a032a JDBCException E net.sf.hibernate.util.JDBCExceptionReporter  [IBM][CLI Driver][DB2/NT] SQL0530N  The insert or update value of the FOREIGN KEY "DB2ADMIN.CSTMR_GM_WN_AMNT_ODD.SQL040112104121950" is not equal to any value of the parent key of the parent table.  SQLSTATE=23503

[1/12/04 10:44:30:877 EST]  32a032a JDBCException E net.sf.hibernate.util.JDBCExceptionReporter  could not insert: [escratch.hibernate.CstmrGameWinAmountOdd#escratch.hibernate.CstmrGameWinAmountOdd@75887588[gameWinAmnt=escratch.hibernate.GameWinAmount@59205920[gameWinAmountId=1,game=escratch.hibernate.Game@27742774[gameId=0]],cstmrGame=escratch.hibernate.CstmrGame@1ddd1ddd[cstmrGameId=1]]]
[1/12/04 10:44:30:897 EST]  32a032a JDBCException E net.sf.hibernate.util.JDBCExceptionReporter  TRAS0014I: The following exception was logged COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0530N  The insert or update value of the FOREIGN KEY "DB2ADMIN.CSTMR_GM_WN_AMNT_ODD.SQL040112104121950" is not equal to any value of the parent key of the parent table.  SQLSTATE=23503

   at java.lang.Throwable.<init>(Throwable.java)
   at java.lang.Throwable.<init>(Throwable.java)
   at java.sql.SQLException.<init>(SQLException.java:51)
   at COM.ibm.db2.jdbc.DB2Exception.<init>(Unknown Source)
   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)


Does anyone know what log level or other trick i need to do to see the actual values being set on the prepared statement. I know that if the prepared statement succeeds then the parameter values are shown but I need to see them if they fail. I'd like to verify that the values are indeed violating the above db constraints. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
log4j.logger.net.sf.hibernate.type=debug


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 1:29 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
The problem is my log4j.properties file is not being found (or another file is being found) on the server and hence setting to debug is not working.

I'll ensure that my log4j.properties is specified as a system property to ensure it gets used.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 2:58 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
Using WSAD5.0.1 (WebSphere 5) and it doesn't want to find my log4j.properties file.

Hibernate seems to get an instance of Log4J that has been configured for the WAS server. Obviously this does not have the properties for debug set to true.

I am wondering if anyone else has had problems of hibernate not using the log4j.properties configured by the system property log4j.configuration.

JC


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 10:27 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Websphere 5.0x has struts, and commons logging ... and i'm not sure how you're configuring your classloader (parent_first, parent_list?)

Anyway, this is how we get it to work using parent_last
(We don't have ejb's, so when i say classpath here, i mean the root of the wsad "java source" directory in the "web project"

1. create a blank file called commons-logging.properties (root of classpath)

2. put log4j.properties on classpath

should help.

James


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 2:01 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
still didn't work. Just does not want to use my log4j.properties (from within hibernate.jar). My own Struts actions log using log4j and of course those do work with my log4j.properties.

For some reason all log4j calls within hibernate.jar are using a logger configured through a set of default WSAD WAS server log4j properties.

I'll do some more research to see if I can get it to use my version and post the fix here if it works.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 12:32 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
WSAD 5.1 with WAS 5.0 and Struts 1.1
logging the prepared statement parameters to the output console for debugging purposes.

1. Goto C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib
2. Unzip the commons-logging-api.jar
3. Add a properties file called simplelog.properties to the commons-logging-api.jar
with the following property:

Code:
org.apache.commons.logging.simplelog.defaultlog=debug


4. Zip the jar backup and replace the existing jar


1. Goto C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib
2. Unzip the ws-commons-logging.jar
3. Modify the commons-logging.properties file. It should read as follows:

Code:
#org.apache.commons.logging.LogFactory=com.ibm.ws.commons.logging.TrLogFactory
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl


4. Zip the jar backup and replace the existing jar


Re-start your WAS server in your WSAD test environment. Debug statements should now be available on the console.

This solution is clearly not optimal as it modifies run-time components of WAS. This can be tolerated if this is in your development environment only. If anyone can figure out how to do this with property files inside the deployable ear file this would be the preferred way to get the hibernate debug logging.

The problem is that WAS uses commons-logging upon WAS startup and sets the Logger to be used. When hibernate calls

Code:
LogFactory.getLog(xxx.class);

The default logger that was initialized upon WAS server startup is used. This logger does not have default log level of less than INFO. This needs to be changed so that the default log level is at least DEBUG in order to see the values of the hibernate parameters in the prepared statements.

There also is probably some programmatic methods to set the Logger to be Log4J with a default log level of DEBUG after WAS startup. Again if anyone figures this out please post your solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 11:42 am 
Beginner
Beginner

Joined: Mon Sep 01, 2003 10:52 am
Posts: 23
Location: UK
As anyone got any further with this as I am facing exactly the same problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 6:14 am 
Beginner
Beginner

Joined: Thu Jun 24, 2004 1:04 pm
Posts: 35
Location: Minnesota - USA
I'm currently using WSAD 5.1.2 with the WAS 5.1 Test server...

I was able to get this debug information without all the messing around with the libraries. Trick is understanding how IBM trace logging works. Read here: http://www.webspherepower.com/issuespri ... 01281.html

What you do then is set the 'Trace Specification' to the below and look at the trace.log

net.sf.hibernate.type.*=all=enabled

I've not figured out how to get this sent to the Console (if even possible). Gave up after few minutes, not worth the headache at this point.

--gus


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.