-->
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.  [ 3 posts ] 
Author Message
 Post subject: hibernate.showsql=true not showing substitution variables
PostPosted: Sat Mar 12, 2005 1:55 pm 
Newbie

Joined: Sat Mar 12, 2005 1:42 pm
Posts: 7
Location: MN
I am trying to debug why my dynamic specification of the order by column is not working. I set showsql to true and below is what I get (i.e. question marks where there should be the value of my variable). It works just fine when I hard code the name of the column I want to order by, but when I try to do a variable substitution it doesn't seem to work. I am guessing when I use setParameter, setString, or setText on the orderByColumn variable that it is putting quotes around the value in the order by clause. I am wondering how others are doing this? I know I can get around it by developing the query string outside of Hibernate first and then feed it to the .createQuery method, but them I lose Hibernates nice features.

Thanks in advance for any help,
Aaron Bartell

Hibernate version:
Hibernate 2.1.3

Name and version of the database you are using:
MySQL 4.1

The generated SQL (show_sql=true):

Hibernate: select document1_.uid as uid, document1_.name as name, document1_.descr as descr, document1_.created as created, document1_.createdby as createdby, document1_.guid as guid, document1_.uploadbytes as uploadby7_, document1_.uploadname as uploadname, document1_.uploadtype as uploadtype, document1_.status as status, document1_.perdocpricecode as perdocp11_, document1_.perpagepricecode as perpage12_, document1_.activedate as activedate, document1_.deactivedate as deactiv14_, document1_.pages as pages from userdocumentasc userdocume0_, document document1_ where (userdocume0_.documentuid=document1_.uid )and(userdocume0_.useruid=? ) order by ? DESC


Java Code
Code:
            Query qry = null;
            qry = DBConn
                    .sess()
                    .createQuery(
                            "select doc from com.dao.Userdocumentasc uda,"
                                    + " com.dao.Document doc"
                                    + " where uda.documentuid=doc.uid and uda.useruid=:useruid order by :orderByColumn DESC");
            qry.setInteger("useruid", useruid.intValue());
            qry.setString("orderByColumn", orderByColumn);


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 2:50 pm 
Beginner
Beginner

Joined: Fri May 21, 2004 12:21 pm
Posts: 22
Location: Sacramento CA, USA
1. You can use log4j as your logger and set your log level as net.sf.hibernate=DEBUG then you can see the binding parameter (the value for?).
2. You can use p6spy which will capture all the sql issued to the database.

You can choose either one of them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 13, 2005 4:12 am 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Anytime you are dymamically building queries, run to the Criteria API first:

Code:
List list = sess.createCriteria(Document.class)
   .createCriteria(Userdocumentasc.class)
      .add(Restrictions.eq("userid", useruid.intValue()))
   .addOrder(Order.desc(orderByColumn))
   .list()


That's not tested, but you get the idea.


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