• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate - show SQL statements with params

 
Ranch Hand
Posts: 105
  • 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: 105
  • 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.
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic