-->
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.  [ 9 posts ] 
Author Message
 Post subject: sql statement logging (only questionmarks)
PostPosted: Mon Sep 01, 2003 10:36 am 
Newbie

Joined: Mon Sep 01, 2003 12:31 am
Posts: 5
Hi,

In my hibernate log, all is see for insert/update statements is something like (insert into table values (?,?,?)).

What do I need to set to see the actual values being sent to the database?
I am using Hibernate 2.2 with mySql.

_________________
Thanks,
Tahir


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 1:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You would need to use a jdbc-level tracer. Check out the p6spy project for an open source implementation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 6:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can just enable debug-level locgging for


net.sf.hibernate.type


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 7:02 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
For P6Spy, keep in mind though that even it's "effective SQL string" output is just P6Spy's best guess.
Unless I'm much mistaken, your variables actually get inserted into the statement (bound) inside the DB server, that's kind of the point of them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, exactly!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 7:33 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
I am using Hibernate 2.2
...

Do you mean 2.0.2?
If not, how did you get 2.2?
I'm eagerly awaiting the <join> I saw on the road map. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 12:07 pm 
Newbie

Joined: Thu Sep 04, 2003 9:20 am
Posts: 3
gavin wrote:
You can just enable debug-level locgging for
net.sf.hibernate.type



Tried this, debug gives a lot more information than I would want to see.
What would be very useful (at an info or debug level), is to see
the query followed by the values of all bind parameters, e.g.

SELECT * from EMP where LST_NAME = ?
[Parameter 1] SMITH

I'm evaluating Hibernate to replace a framework that we built in-house.
Ours is not an O/R mapping, it's more of an API that sits above JDBC.
One of its features is that it lets us log the values of bind parameters
as in the example above.
Alternatively (depending on a configuration setting), the values can be automatically substituted in place of the ? marks. So the above query
would get logged as:

SELECT * from EMP where LST_NAME = 'SMITH'

The latter is more expensive to do, however we've found it to be
invaluble during debugging and troubleshooting since we can simply
copy the SQL and run it directly against the DB to see what's going on.
Helps a great deal for large queries with many parameters.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 5:02 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
As last solution, you can always turn MySQL logging on - all statements will be recorded together with the actual parameter values ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 7:56 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
dsatanov wrote:
SELECT * from EMP where LST_NAME = 'SMITH'


P6Spy does exactly that.

Plus, P6Spy allows you to:
    see timings for how long each query took
    see info about transactions (when commit/rollback are called)
    filter statement logging using a pluggable regex library
    filter statements by how long they took to execute (i.e. you can tell P6Spy to only log statements that took a long time)
    see info about result set iteration
    see info about statement batching


There's also an open source project, SQL Profiler, that allows you to gather and view aggregate statistics on the queries issues by your app using P6Spy. You can use SQL Profiler to see things like which queries are issued most often and stuff like that.

It comes down to the principal "do one thing well".
Don't ask Hibernate to be implement a sophisticated SQL statement logging facility, becuase that's what P6Spy does. P6Spy does SQL logging better than Hibernate ever will because logging SQL statements is not the goal of Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.