-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Logging SQL queries with parameters in Log4j
PostPosted: Sat May 12, 2007 2:54 am 
Newbie

Joined: Mon Apr 16, 2007 10:44 am
Posts: 9
Hi,

Is it possible to log the SQL hibernate executes with Log4j (with parameters)?

I would like to gauge the effectiveness of second level caching by looking at when certian SQL statements are being executed.

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 12, 2007 10:53 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Yeah.. use this in hibernate.cfg.xml

Code:
<property name="show_sql">true</property>
<property name="format_sql">true</property>

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 8:06 pm 
Newbie

Joined: Mon Apr 16, 2007 10:44 am
Posts: 9
This method displays question marks instead of parameters:

... WHERE age = ?

Ideally I would like the following to be displayed:

... WHERE age = 21


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 11:18 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Akumadevil,

That’s the problem I agree. In one of my project, I was working with SQL Tuning and performance optimization. I found lot of problem in extracting Query and sending it to DBA . It was very complex JOB for me. If there is really any solution Plzz.. share it with me.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 12:16 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,

We might not get a query that can be directly fired at prompt.

Reason:
If I understand it correctly, the operations that take place are, ( done by Hibernate )
i) set the values into host bind variables.
ii) fire the query as-is with bind variables to underlying database.

A query of the form,
"select * from my_table where age = 21"
is never formed. ( assume 21 is the bind value )
What gets fired is
"select * from my_table where age = ?"
with bind variables holding the value 21.

Correct me if I am wrong.

However, to know the values of bind variables, you can use,
log4j.logger.org.hibernate.type=debug

------------------------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 12:29 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi pramodkp,

Are you talking to do it manually? In any application there are thousand of update insert statements .So if average one table contain 20 field and if 100 tables are there then may be binding value would be 20*100*1000 assuming in worst case. Is that possible to give report to DBA about that much Query.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 12:40 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
This was discussed, some time back at http://forum.hibernate.org/viewtopic.php?t=965749&postdays=0&postorder=asc&highlight=sql+log&start=0


Top
 Profile  
 
 Post subject: Using P6Spy
PostPosted: Mon May 14, 2007 12:49 am 
Newbie

Joined: Tue Dec 12, 2006 9:07 am
Posts: 13
To view the query with the values set in the where condition, configure P6Spy.

The installation can be downloaded from

http://www.p6spy.com

Read the instructions on the site to configure it for your environment.
If you are connecting using connection url in hibernate configuration file, then change the connection driver class to
Code:
com.p6spy.engine.spy.P6SpyDriver
and modify the realdriver property in spy.properties to your original database driver.
For eg: if it is an oracle driver then realdriver=oracle.jdbc.driver.OracleDriver.

Place p6spy.jar and spy.properties in the classpath and restart your application. You should find the queries with the values set logged
in spy.log.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 1:43 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi jaikiran ,

Thanks to remind me that patch .But is it avaliable with Hibernate API.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 9:55 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Quote:
But is it avaliable with Hibernate API


Not that i am aware of


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.