-->
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.  [ 5 posts ] 
Author Message
 Post subject: Getting Hibernate to show me the query parameters
PostPosted: Wed Oct 26, 2005 4:18 am 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
I'm using Hibernate 3.1rc with Java 1.5 on Linux. All this is running within Apache Tomcat 5.5.

Is there a way to get Hibernate to show me the actual query parameters? I have tried the obvious things: I put log4.jar into the application classpath. I created a log4j.properties that looks like this:

Code:
### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=/tmp/hibernate.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=warn, stdout

#log4j.logger.org.hibernate=info
log4j.logger.org.hibernate=debug

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
#log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
#log4j.logger.org.hibernate.type=info
log4j.logger.org.hibernate.type=debug

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug

### log cache activity ###
#log4j.logger.org.hibernate.cache=debug

### log transaction activity
#log4j.logger.org.hibernate.transaction=debug

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace


That is in the classpath, right next to hibernate.cfg.xml, and yet nothing shows up in /tmp/hibernate.log. Surely there's some way for Hibernate to do some logging? I notice that it won't start up unless it can find the Commons Logging package, and Commons Logging claims to be able to work with log4j. Any ideas on this?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 4:28 am 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
Ah, never mind. I had set the appender wrong. It should be:
Code:
log4j.rootLogger=warn, file

I think.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 4:29 am 
Newbie

Joined: Wed Apr 20, 2005 4:14 am
Posts: 10
Location: Netherlands
Here's my log4j.properties. Yours is somewhat more complicated, but I guess the entry 'log4j.logger.org.hibernate=debug' should do the trick.

Code:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

log4j.rootLogger=warn, stdout

log4j.logger.org.hibernate=debug

I have the last entry is always set to 'error', but when I change it to 'debug' I get all the query-parameters.

When I'm debugging, I get entries like this in my log (which in my case is written to the console).
Code:
Hibernate: select gebruiker0_.ID as ID, gebruiker0_.NAAM as NAAM28_, gebruiker0_.INLOGNAAM as INLOGNAAM28_, gebruiker0_.PASSWORD as PASSWORD28_ from Gebruiker gebruiker0_ where (gebruiker0_.INLOGNAAM=?)
10:30:51,677 DEBUG AbstractBatcher:343 - preparing statement
10:30:52,438 DEBUG QueryLoader:228 - bindNamedParameters() beheerder -> zoeknaam [1]
10:30:52,448 DEBUG StringType:59 - binding 'beheerder' to parameter: 1


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 10:35 am 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
If you just want the stored procedure bind parameters use

org.hibernate.type = DEBUG

in either log4j.properties or log4j.xml.

Note that the log setting for params is cached statically, so if your logging config is reloaded automatically the change wont "take" until you restart your server or application.

Also, this is almost useless without setting the show SQL flag to true (via hibernate-config, not via logging).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 10:35 am 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
and of course use net.sf.hibernate.type in Hibernate 2.x.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.