Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2008, 03:23 PM
Member
 
Join Date: Mar 2008
Posts: 1
altaf is on a distinguished road
Hibernate order by query thru java solution urgently reqd
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 rderBy
(the colon before orderBy is not visible because of the smiley it is actually orderBy: 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.

please suggest some solution other than the one i have provided my self
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hibernate sql query taicode Database 0 03-25-2008 05:17 PM
Problem with applying Sql order by to html table sireesha264 Advanced Java 2 02-04-2008 11:20 AM
Please Help - Java Date/Countdown Query desktop_doodle New To Java 2 01-08-2008 05:53 PM
please help urgently ananas7777 New To Java 1 12-22-2007 03:48 AM
adding a variable in order to a list Jrr New To Java 2 11-19-2007 02:10 AM


All times are GMT +3. The time now is 12:53 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org