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

hibernate.show_sql

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The definition for this property is:

Write all SQL statements to console (a minimal alternative to the use of the logging functionality as described in Chapter 10)


Anyone have a recommendation of how I can get all sql statements to write to a log file instead of a console? The console logging works fine when I am running the application locally but when the application is running in a hosted environment the console logging does no good. It sounds easy but I have struggled with finding a way to do this. Also, I do not want to simply set the logging level (log4J) to debug. I only want the sql statements.
Thanks!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is really a log4j question. You need to configure an file appender and set a category for the Hibernate class that logs the messages (I forget exactly which one it is - but run it once with the show_sql property set and you'll see).

Configuring appenders and categories is better covered in Other Open Source Projects. I'm moving this to there.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I do not want to simply set the logging level (log4J) to debug. I only want the sql statements.


If you are using Hibernate-2.x, add the following to your log4j.xml:



If you are using Hibernate-3.x, add the following to your log4j.xml:


 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While it is sort of a log4j question it is a bit more specific to Hibernate and I have a good discussion regarding it that has nothin gto do with log4j. So I am moving this back to the ORM forum.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, jaikiran wrote what basically to put into the log4j.xml, but you add that to one of the file appenders already in that file, if you use JBossAS also.

Anyway, I also wanted to point you to p6spy. This will show you every call through jdbc with all the values. Where show_sql shows the "statement, but no values and it isn't too pretty, even if you use the format-sql tag.

Mark
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those are excellent ideas. Thanks very much!
Andy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic