Thursday, October 29, 2009

Toggle Hibernate "Show SQL" at Runtime

Okay, the title is a bit deceiving. As far as I know, you cannot modify the value of the configuration property "hibernate.show_sql." However, that does not prohibit you from toggling at runtime whether SQL statement are output to your log files.

Why would you want to do this?
Because turning on "show_sql" will flood your logs with all the SQL generated by hibernate, making it difficult to find a particular section you might be debugging or optimizing. Being able to toggle the output of SQL allows you to enable it just for the sections of code you are investigating.

First, the solution, then I'll get to why:

import org.apache.log4j.*;


Logger sqlLogger = Logger.getLogger("org.hibernate.SQL");

... do your stuff ...


So what's going on here?
The key is knowing what "show_sql" does and that it is not the only way to log the SQL statements generated by hibernate. Namely, "show_sql" sends all SQL to the standard output, but hibernate also uses Apache Commons Logging. So, as long as you configure commons logging to use an underlying logging framework that supports changing log levels at runtime, you can toggle the output of SQL by getting a hold of the "org.hibernate.SQL" logger and bending it to your will.


Anonymous said...

This i great, used it in my own development work at our Swedish yellow pages project

Anonymous said...

This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion

mas jangkrik said...

Cool post very informative I just found your site and read through a few posts although this is my first comment, i'll be including it in my favorites and visit again for sure. jual glutera

crocs surabaya said...

This site is awesome. My spouse and i constantly come across a new challenge & diverse in this article.

AdiB said...

This is great but it will not give you the bind variables value.
Seems like this is impossible in runtime due to NullableType.IS_TRACE_ENABLED

distributor baju anak said...

I would like to apprentice at the same time as you amend your site, how can i subscribe for a weblog site?

mas jangkrik said...

Thank you for the great article I did enjoyed reading it, I want to encourage that you continue your great job, have a good day. paket umroh murah

acaiberry asli said...

Wow this post give truly quality information . Really very useful tips are provided here .

mas jangkrik said...

Thanks for sharing this great article!

mas jangkrik said...

Wow...there are more valuable information in this site. we can learn more from this site. Thanks for share jasa pembuatan website

mas jangkrik said...

Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need! Keep Post ^_^ jasa pembuatan toko online

Anonymous said...

Took me time to read all the comments, but I really enjoyed the article. Grow Up

Anonymous said...

Great info. I love all the posts, I really enjoyed, I would like more information about this, pulau tidung

mas jangkrik said...

Oh! So nice. You did really so wonderful job. You have posted very informative thing. I am excitedly waiting for you next post. jual glutera

mas jangkrik said...

Hello, i am not accustomed to passing comments on discussions, but i am quite astounded by this site, so i will definitely visit again produk pemutih gigi

mas jangkrik said...

Iam very happy to reading, Hope you continue to share your information more produk penghilang jerawat

mas jangkrik said...

Great article, Very good and useful information. Iam very happy visit your site. Thanks for sharing. acai berry murah

mas jangkrik said...

Great!!! I have gain a lot from your article. thanks so much you provide really well information. visit here

Aney Collmeyer said...

We are having high interest to supply the reader points that cover the re enter values to control it.
buy facebook likes
buy youtube views

Aney Collmeyer said...

This content were widely shared since it has the desire quality on the social platform.
buy instagram followers
buy instagram followers

mas jangkrik said...

I really fun with your Blog, I would like more information about this, because it is very nice., Thank You

mas jangkrik said...

Awesome information, Any way I'll be subscribing to your feed and I hope you post again soon. Keep Blogging

mas jangkrik said...

Amazing, it's contain great and unique information. I like to share it with all my friends. Thank jual emilay

Lauren anderson said...

Thanks for the good article I did enjoyed reading it, I need to encourage that you just continue your nice job, have a nice day. Exclusive Company Escorts

mas jangkrik said...

You've written nice post, I am gonna bookmark this page, thanks for info. Thumbs Up jasa sewa mobil jogja

kakang kokong said...

thanks for inspiring me :) .... mobil sedan corolla

Herbalmedika Online said...

The material articles is very foreign to me, but tasty as well read, greetings successful

Obat Herbal

Anonymous said...

I would like to apprentice at the same time as you amend your site, how can i subscribe for a weblog site?
pusat baju anak

James Smith said...

This works perfectly for the right time after the last great chance. Well optimized content too.

pengolahan air bersih said...

This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion

druze catering said...

Amazing.. this is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Thanks for sharing

Baju Anak Murah said...

Thank you untuh this article. really helped me to increase knowledge about this issue.

Otomotif Bandung said...

Such a nice information you shared in this article, I really like it.

Honda Mobilio Bandung
Suzuki Ertiga Bandung
Chevrolet Spin Bandung
Daihatsu Xenia Bandung
Pajero Sport Bandung
Honda Mobilio Bandung

Bridal saree said...

I very much to like and agree with your point of view. Thank you for sharing. At the same time, I love best pram very much .Welcome to look at my website and blog articles.

quya said...

Its such an amazing post, I really like it.

Dian Rahadian said...

Its such an amazing post, I really like it.

Dian Rahadian said...

Its such an amazing post, I really like it.

Harga Mobil Murah Bandung
Harga Mobil Chevrolet Bandung
Harga Mobil Daihatsu
Harga Mobil baru Honda
Harga Mobil Murah Suzuki
Harga Mobil baru Mitsubishi
Harga Mobil Murah Mazda
Harga Mobil Ford
Harga Mobil Kia Bandung
Harga Mobil baru Toyota
Harga Mobil Murah Nissan

Imron Rosadi said...

Looks greats, thanks for shared aneka resep kue basah praktis

aneka resep kue basah said...

Always looks amazing aneka resep kue basah praktis

karya ismail said...

This is a great article, Thanks for giving me this information. Keep posting
Furniture Jepara :
Mebel Jepara :
Furniture Jepara Murah :
Furniture Minimalis :
Furniture Jati Jepara :
Furniture Online :
Furniture Jati Jepara :
Furniture Murah :
Furniture Kursi :
Furniture Jati Jepara :
Karya Priboemi Jepara :
Furniture Kursi Jati :
Furniture jepara Online :
Furniture Online jepara :
Furniture Meja :
Furniture Online :
Kamar Set Minimalis
Kursi Tamu Mewah
Meja Makan Jati Jepara
Tempat Tidur Jati Jepara
Mebel Jati Jepara
Mebel Jepara
Kamar Set Jati

sewa mobil surabaya said...

sewa mobil surabaya, kami berkomitmen untuk memberikan harga ekonomis untuk pelanggan dengan harga sewa paling murah di surabaya, tentunya dengan tidak mengurangi kualitas pelayanan untuk pelanggan. Cs: 03171500666 / 03181500666 / 085232729729

Malih Tongtong said...

This is my very first time i visit right here. I found so numerous interesting stuff in your weblog particularly its discussion. harga mobil honda harga honda mobilio baru

Pusat Les Privat said...

This is really wonderful website. If you need this rental mobil di Pare and also you can find this Les privat guru ke rumah siswa di Surabaya

Pusat Les Privat said...

This website is really wonderful . If you need this
guru les privat ke rumah di Surabaya
Les privat guru ke rumah siswa di Jogja
ojek dan rental motor di Pare kampung inggris
rental motor dan ojek di Pare Kediri
Kursus Bahasa Inggris di Pare Kediri
guru les privat bahasa inggris ke rumah
Les privat Surabaya
Guru les privat TK di Surabaya
Les privat untuk SD di Surabaya
Les privat SMP/MTS di Surabaya
Les privat SMA/MA/SMK di Surabaya
Les privat TK,SD,SMP,SMA,Mahasiswa,Karyawan, dan Umum di Surabaya
Penyedia Guru les privat semua mata pelajaran di surabaya

Mukhamad Lubab said...

bisnis ebook. baca disini.
Baca ebook novel cinta. baca disini.
Baca Jual mukena al gani?. baca disini saja.
Baca Penjelasan mukena al gani, baca disini
Bacatentang memulai bisnis. baca disini.
Baca tips bisnis elbuy. baca disini
ebook novel? baca disini said...

polo ralph lauren
true religion outlet
burberry outlet
nfl jerseys wholesale
kobe bryant shoes
coach factory outlet
kobe 10 shoes
vans shoes sale
true religion jeans sale
instyler max
oakley sunglasses
gucci belts
michael kors outlet clearance
louis vuitton outlet
jordan 11 concord
coach outlet online
toms outlet
toms shoes
jordan 3 white cenment
kevin durant shoes 7
jordan retro
polo outlet
gucci outlet
cheap air jordans
jordan 4 toro
coach outlet
ray ban sunglasses
jordan 3
gucci handbags

aaa kitty20101122 said...

air jordan
michael kors handbags
kyrie irving shoes
led shoes for kids
links of london outlet store
lebron 14
light up shoes
yeezy boost
michael kors outlet
nike air huarache

aaa kitty20101122 said...

adidas nmd
air jordans
adidas tubular
golden goose
air max 2016
true religion outlet
kobe shoes
nike polo
jordan 11 retro

learn to fly 2 said...

Nice post. It would be great to read more about this theme .

Les privat Jogja said...

Thanks for sharing this. I am glad to find this and it is very interesting.
you can visit this
Les privat guru ke rumah siswa di Jogja
les privat di Jogja guru ke rumah siswa
Guru les privat datang ke rumah siswa di Jogja

luckys said...

lucky patcher

洛噷 said...

2018625 leilei3915
michael kors outlet online
asics shoes
coach outlet
christian louboutin outlet
moncler jackets
christian louboutin sale
michael kors outlet clearance
ray ban sunglasses outlet
canada goose jackets
polo ralph lauren outlet

洛噷 said...

2018930 leilei3915
canada goose outlet
ugg,uggs,uggs canada
canada goose uk
moncler jackets
ugg boots
kate spade outlet store
ugg boots
coach outlet
polo ralph lauren
kate spade handbags