-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate order by query thru java solution urgently reqd
PostPosted: Thu Mar 13, 2008 1:17 am 
Newbie

Joined: Wed Mar 12, 2008 9:39 am
Posts: 1
hi,
i am using java with hibernate . i want to run a hibernate order by query thru java.
i have written the query in hibernate.hbm.xml file. the query is as follows:

query
SELECT distinct a.process_id, a.name name, a.category_id,c.parent_id
FROM tbl_process_master a, tbl_category c where (lower(a.name) like :searchString or lower(a.description) like :searchString or
lower(a.meta_tag) like :searchString ) and a.status=:status and a.category_id=c.cat_id
order by :orderBy

(orderBy is passed from java method as a parameter)
public List getSearchResult(String searchString, status,String orderBy {

the java method calling this query contains follows only the calling of query is written below rest has been omitted as it is not reqd.:


Session ss=s.openSession();
List ProcessList1 = ss.getNamedQuery("getSearchResultForProcess1")
.setString("searchString", searchString)
.setString("status", status)
.setString("orderBy", orderBy)

then i iterate the List.

the problem is the query works fine if i write the script directly from sql command window or i write the query as

above query order by ' " + orderBy+" '

and orderby also works based on the parameter given to it.
but when i try to run the same query thru hibernate ie writing the query in hibernate.hbm.xml file and passing the orderby parameter thru a java method aas described above the query runs but orderby does not happen

PROBLEM
The problem is that hibernate converts the orderby parameter as 'orderBy' and then tries to do order by with those quotes.as there is no col name or col no. with the 'orderBy' the orderby clause does not get fired.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.