-->
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: How to view the generated SQL
PostPosted: Thu Aug 18, 2005 2:59 pm 
Newbie

Joined: Thu Aug 18, 2005 2:50 pm
Posts: 4
how to view the generated SQl ? I can see the HSQL but wanted to see what it translates to when the HSQL exactly hits the database.

I presume there is a config file where I can turn on the sql trace.

_________________
regards,
vas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 3:01 pm 
Newbie

Joined: Fri Jan 07, 2005 5:46 pm
Posts: 19
Use hibernate.show_sql true in either hibernate.properties or the corresponding XML syntax in hibernate.cfg.xml


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 3:02 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Or put these in your hibernate.cfg.xml

<property name="show_sql">true</property>
<property name="use_sql_comments">true</property>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:18 pm 
Newbie

Joined: Thu Aug 18, 2005 2:50 pm
Posts: 4
a5sk4s wrote:
Use hibernate.show_sql true in either hibernate.properties or the corresponding XML syntax in hibernate.cfg.xml


I already have that and this is what I see in the console



The reason why I want to see this is I am not able to retrieve an Object and I thought looking at the sql would a starting point and then I can move on further.

Code:
public Panel loadByName(final String name) {
        return (Panel) getHibernateTemplate().execute(new HibernateCallback() {
                    public Object doInHibernate(Session session)
                        throws HibernateException {

                        String query = " from Panel p where p.name = :name ";
                        Query queryObject = session.createQuery(query);

                        queryObject.setString("name", name);
                       
                        List panels = queryObject.list();
                        // the list that i got back is null.


                        return null;
                    }
                });
    }


this is what i see in console.

Code:
10:35:46,758 INFO  [STDOUT] Hibernate: select panel0_.OBJECTID as OBJECTID, panel0_.LOCKVERSION as LOCKVERS2_, panel0_.CREATION_DATE as CREATION3_, panel0_.NAME as NAME, panel0_.TITLE as TITLE from PANEL2 panel0_ where (panel0_.NAME=? )
10:36:48,637 INFO  [STDOUT] Hibernate: select panel0_.OBJECTID as OBJECTID, panel0_.LOCKVERSION as LOCKVERS2_, panel0_.CREATION_DATE as CREATION3_, panel0_.NAME as NAME, panel0_.TITLE as TITLE from PANEL2 panel0_ where (panel0_.NAME=? )


see that the place holder is not replaced with what ever String that I had set it to?

_________________
regards,
vas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:50 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
If you want to see what values are bound to the parameters, enable DEBUG logging in the org.hibernate logger

e.g.:

Code:
<logger name="org.hibernate" additivity="false">
      <level value="DEBUG"/>
      <appender-ref ref="SomeFile"/>
   </logger>


in log4j.xml.

You don't see the values replaced in the SQL output because that is done through JDBC.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 5:16 pm 
Newbie

Joined: Thu Aug 18, 2005 2:50 pm
Posts: 4
nathanmoon wrote:
If you want to see what values are bound to the parameters, enable DEBUG logging in the org.hibernate logger

e.g.:

Code:
<logger name="org.hibernate" additivity="false">
      <level value="DEBUG"/>
      <appender-ref ref="SomeFile"/>
   </logger>


in log4j.xml.

You don't see the values replaced in the SQL output because that is done through JDBC.


thank you I will do that.

By the way I could retrieve an Object and here is what I did

the name parameter was a String with white spaces and I replaced it with a name that did not have any white spaces and it worked. what is it that I would have to do inorder to pass a String with empty spaces like
"String with spaces" ?

_________________
regards,
vas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 5:56 pm 
Newbie

Joined: Fri Jan 07, 2005 5:46 pm
Posts: 19
Your database may provide an SQL profiler, or you could use something like P6Spy (http://www.p6spy.com/), which works transparently as a JDBC data source.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 6:41 pm 
Newbie

Joined: Thu Aug 18, 2005 2:50 pm
Posts: 4
a5sk4s wrote:
Your database may provide an SQL profiler, or you could use something like P6Spy (http://www.p6spy.com/), which works transparently as a JDBC data source.


thanks for all the replies guys. I found the problem and didn't have to fix it ;-). I was logging in as a different schema user who does not have all the permissions to view some objects. bummer .....

_________________
regards,
vas


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 20, 2005 1:43 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
So give one of us the points.


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.