Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help, how config Hibernate to show the real SQL?

 
sam joe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I can change property

hibernate.show_sql true

to show part of the SQL as

update SEQUENCE set I_SEQ=?, C_UPDATE_UID=?, T_STMP_UPD=? where C_TABLENAME=? and C_COLNAME=?

But is there anyway to show the real value instead of question mark?

Thanks in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Directly below that debug Hibernate should be logging what values it is replacing the question marks with.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From this thread, you need to change one class's log level to DEBUG:Why this isn't another option, like "show_sql_params" beats me.

Another option is to use the P6Spy JDBC driver wrapper. It logs all SQL, including result sets, to a log file.
 
sam joe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No luck, I still get the same thing. Here is my log4j.properties, is there something wrong with those parameters?
=========================================
### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=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.net.sf.hibernate=info
log4j.logger.net.sf.hibernate=debug

### log just the SQL
#log4j.logger.net.sf.hibernate.SQL=debug

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

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

### log cache activity ###
#log4j.logger.net.sf.hibernate.cache=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace
[ January 11, 2005: Message edited by: sam joe ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That file looks correct. Is there another log4j.properties file (in a JAR or elsewhere) that is taking precedence? I just tried it myself (with debug in both lower- and uppercase) and it works for me.
 
sql one
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I set "log4j.logger.net.sf.hibernate.type=debug",

my console will show
Hibernate: insert into UsrGroup (name, description, status) values (?, ?, ?)
16:45:28,822 DEBUG StringType:46 - binding 'GroupName-199' to parameter: 1
16:45:28,822 DEBUG StringType:46 - binding 'Groupdescription' to parameter: 2
16:45:28,822 DEBUG IntegerType:46 - binding '1' to parameter: 3


If you have problem, you can try run a testcase in IDE with a log4j.properties in classpath. Thanks for you help.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sql one:

Welcome to Java Ranch! Please change your display name here. It should conform to the JavaRanch Naming Policy (We are looking for a name that is not obviously fictitious...)
 
Bobby Shah
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that this question is a bit old. But just wanted to post the answer in case someone else needs it.

One can set the logging level to "TRACE", if "DEBUG" is not working in the following property of log4j:

log4j.logger.org.hibernate.type=TRACE
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And while we're on the topic, I found this file provided VERY verbose logging:


### 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
### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=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 'debug' to 'debug' ##

log4j.rootLogger=debug, file
log4j.logger.net.sf.hibernate=debug

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

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=debug

### log prepared statement cache activity ###
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=debug

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic