• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Hibernate - show SQL statements with params

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic