Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - show SQL statements with params

 
Stephane Clinckart
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Stephane Clinckart
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic