wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate - show SQL statements with params Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate - show SQL statements with params" Watch "Hibernate - show SQL statements with params" New topic
Author

Hibernate - show SQL statements with params

Stephane Clinckart
Ranch Hand

Joined: Oct 21, 2003
Posts: 89
Well,

I never succeed to log the SQL statement with the parameters.

Can some one explain me how to do that?

Actually I use mySQL where I can log the queries... but I would like to do it on the hibernate level.

Is there any way to add a customised class to "intercept" the query before execution?

Thanks a lot

Stephane
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You set the property hibernate.show_sql to show the SQL, and add a category to your logging to log debug from the package org.hibernate.types. Or you use P6Spy, or your database's profiler (if it has one).


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Stephane Clinckart
Ranch Hand

Joined: Oct 21, 2003
Posts: 89
Paul Sturrock wrote:You set the property hibernate.show_sql to show the SQL, and add a category to your logging to log debug from the package org.hibernate.types. Or you use P6Spy, or your database's profiler (if it has one).


Hi Paul,

I tried show_sql... who shows effectivly the sql... but not the values of the parameters.
I'm using p6spy on a project... it work good for most of situation. There is also an interesting statistic tool you can use with.

Is there no way to log - or better - intercept the full query (with parameters values) in hibernate?
--> I would like to have some control on my sql when using hibernate in specifics cases.

Thanks a lot.

Stephane
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I tried show_sql... who shows effectivly the sql... but not the values of the parameters.

Indeed, this is why you need to log debug from org.hibernate.types. You should then see the SQL with ?s followed by the value bound.


I would like to have some control on my sql when using hibernate in specifics cases.

You can use SQL queries directly in Hibernate. Check out the methods available in the Session class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate - show SQL statements with params
 
Similar Threads
Bytecode enhancement controversy
How to Set Primary / Foreign Keys or Relationships with Hibernate 3 / JPA Tables?
To log sql in Hibernate
Hibernate Issue
converting from Hibernate to JDBC???