-->
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.  [ 8 posts ] 
Author Message
 Post subject: show_sql and bind variables?
PostPosted: Wed May 18, 2005 5:03 am 
Newbie

Joined: Wed May 18, 2005 4:50 am
Posts: 18
I am new to Hibernate so please excuse me, if this is a "stupid" question. But I have been searching the net for an answer for some time now and could not find anything useful ...

After setting

hibernate.show_sql true

in the properties file, the SQL statements generated by hibernate are logged like this

Hibernate: update PERSON set name=?, lastname=?, age=? where id=?

Is there a way to enabled logging of the "values" for the bind variables?
Something like

Hibernate: update PERSON set name='John', lastname='Doe', age=30 where id=42

In other projects I worked on (without Hibernate) we always had a special subclass of PreparedStatement for this and it has proven very useful for debugging purposes.

Thanks in advance.

Bye,
Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 7:57 am 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
Try logging sql with this: http://www.p6spy.com/

Reto


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 8:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - so why dont you use that preparedstatement class ? ;)

You can also look into p6spy which can do some of this.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 9:13 am 
Newbie

Joined: Wed May 18, 2005 4:50 am
Posts: 18
I will certainly look into "p6spy" and maybe even plug our own PreparedStatement into Hibernate.

But I was actually hoping that this was a standard feature of Hibernate. Something like

Code:
hibernate.show_sql true
hibernate.show_sql_parameters true


Since Hibernate is "filling in" the values for the bind variables anyway, it should be "easy" to print them to the log ...

I am currently evaluating Hibernate for an upcoming project and I am quite impressed by what I have seen so far. But all the people to whom I have shown my sample and the generated SQL, have asked me right away "Can you also see the parameter values?"


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 9:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well you can by enabling org.hibernate.type debug log.

but it wont be merged into the sql - for that you should use tools like p6spy etc.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 10:28 am 
Newbie

Joined: Wed May 18, 2005 4:50 am
Posts: 18
> well you can by enabling org.hibernate.type debug log.

That's what I was looking for ... well almost ;-)

Thanks!
Stefan[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 5:56 am 
Newbie

Joined: Tue Oct 18, 2005 11:22 am
Posts: 14
max wrote:
well you can by enabling org.hibernate.type debug log.


How can I set this, if I use JDK Log API?

I tried the following code snippet in my application:
Code:
        Logger rootLogger = Logger.getLogger("");
        rootLogger.setLevel(Level.FINEST);
       
        Logger.getLogger("org.hibernate").setLevel(Level.FINEST);
        Logger.getLogger("org.hibernate.type").setLevel(Level.FINEST);
        Logger.getLogger("org.hibernate.tool.hbm2ddl").setLevel(Level.FINEST);



But the variable values aren't logged. Where's the mistake. TIA


Top
 Profile  
 
 Post subject: Re: show_sql and bind variables?
PostPosted: Fri Oct 08, 2010 8:46 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
You should have defined handler level also. I know this topic is very old, but I seem to get here each time I forget this. So I decided to add this information here.

final ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINEST);
Logger.getLogger("org.hibernate").addHandler(handler);


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