-->
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: issue with hql conversion
PostPosted: Tue Jan 10, 2012 9:28 pm 
Newbie

Joined: Tue Jan 10, 2012 8:29 pm
Posts: 6
Hi,
I have the following native sql query for MySQL
Code:
   top10UserActivityQuery =
        "select sum(trans_cnt) as t_cnt, employeeid as username from map2_data "+
        "where fdate between (:datefrom) and (:dateto) and res_id=:res_id and location =:location "+
        "group by employeeid order by t_cnt desc limit 10;"


considering I have map2_data as my domain class how would the query change in HQL?


Top
 Profile  
 
 Post subject: Re: issue with hql conversion
PostPosted: Thu Jan 12, 2012 10:04 am 
Newbie

Joined: Fri Nov 27, 2009 2:33 pm
Posts: 2
priyank15 wrote:
Hi,
I have the following native sql query for MySQL
Code:
   top10UserActivityQuery =
        "select sum(trans_cnt) as t_cnt, employeeid as username from map2_data "+
        "where fdate between (:datefrom) and (:dateto) and res_id=:res_id and location =:location "+
        "group by employeeid order by t_cnt desc limit 10;"


considering I have map2_data as my domain class how would the query change in HQL?


It will be nearly the same in HQL. Something like:

Code:
   top10UserActivityQuery =
        "select sum(transCnt) as tCnt, employeeId as username from map2Data "+
        "where fdate between (:datefrom) and (:dateto) and resId=:resId and location =:location "+
        "group by employeeId order by tCnt desc;"


The limit would have to be implemented by using setMaxResults() on the query object.


Top
 Profile  
 
 Post subject: Re: issue with hql conversion
PostPosted: Thu Jan 12, 2012 9:28 pm 
Newbie

Joined: Tue Jan 10, 2012 8:29 pm
Posts: 6
Thanks for the tip..!


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.