-->
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.  [ 6 posts ] 
Author Message
 Post subject: Does HQL to SQL vary? selective show_sql=true possible?
PostPosted: Wed Jun 15, 2005 9:28 pm 
Newbie

Joined: Wed Jun 08, 2005 6:03 pm
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:Oracle 9.2.0.4

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hello! I want to see what SQL Hibernate translates a certain HQL to. Can this vary at different executions of the HQL call? What I mean is, can the Oracle SQL query generated by Hibernate given a HQL query be different at different executions?

Is there a way to make Hibernate selectively show the sql that is being run ? I dont want to set the show_sql property to true globally as it will make it pretty much impossible in my case to sift through the large number of sqls that will show up in the log. Ideally I would like to turn on show_sql before and turn off after a particular query is run.

Thanks in advance.

-sudhir


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 3:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
enable/disable the log catagory org.hibernate.SQL using your favorite logging framework.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 9:00 pm 
Newbie

Joined: Wed Jun 08, 2005 6:03 pm
Posts: 7
thanks for your reply. i am using Hibernate 2.1.6. So would the equivalent in that version be category log4j.logger.net.sf.hibernate.SQL or probably just net.sf.hibernate.SQL ?

Or is it that the granular control is available only from 3.0 onwards ?

-sudhir


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 10:37 pm 
Beginner
Beginner

Joined: Mon Jun 13, 2005 5:52 pm
Posts: 43
In H3:

log4j.logger.org.hibernate.SQL=DEBUG


In H2, if I remember correctly:

log4j.logger.net.sf.hibernate.SQL=DEBUG


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 1:11 pm 
Newbie

Joined: Wed Jun 08, 2005 6:03 pm
Posts: 7
I put this in the code
Code:
        Logger logger = LogManager.getLogger("net.sf.hibernate.SQL");
        logger.setLevel((Level) Level.DEBUG);

before running the HQL and put
Code:
        logger.setLevel((Level) Level.ERROR);

after running the HQL.
The sql satements did not get printed in the log or on the console.
In the log4j.lcf file I added
Code:
log4j.logger.net.sf.hibernate.SQL=debug

but it makes no difference.
The only way I can get the system to print the sql to the log/console is by setting hibernate's show_sql to true in the hibernate.properties file:
Code:
hibernate.show_sql true

But this turns sql logging on for all the sqls whereas I want to turn it on selectively.
What am I doing wrong? It feels like I am missing something obvious!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 1:24 pm 
Newbie

Joined: Tue Mar 22, 2005 5:43 pm
Posts: 16
Location: Teksouth
use
logger.info(sql);

make sure in log4.properties you have following statement

log4j.logger.net.sf.hibernate=INFO, A1, R


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.