473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 :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.
Mar 12 '08 #1
3 2986
BigDaddyLH
1,216 Expert 1GB
I don't think you can do that. Parameters are for values, not for names of columns. You can not parameterize a query by the column ORDER By column.

Alternatives?

You could have multiple queries, one for each column and invoke the appropriates one.

Or you could form the query string in Java using a bit of logic, appending the correct column name.
Mar 12 '08 #2
JosAH
11,448 Expert 8TB
@BD: *ahem* this thread was marked as 'urgent' *cough*

kind regards,

Jos ;-)
Mar 12 '08 #3
BigDaddyLH
1,216 Expert 1GB
@BD: *ahem* this thread was marked as 'urgent' *cough*

kind regards,

Jos ;-)
I tried so send urgent data but OOBINLINE was disabled.
Mar 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jilppe | last post by:
I am creating a report based on a crosstab (BodyPart). This crosstab counts the number of incidents for each body part by month. However the data is for different years and I would like the user to...
0
by: rsoni1011 | last post by:
Hi, How can I read outlook data files (*.pst) thru java code and put the specific mails in the seperate folder.
1
by: jesmi | last post by:
please provide me the function and code for sending sms thru java in .java format so that i can call that function in .jsp page. thanks
3
by: crossroadsk | last post by:
<pre> Hi all, I'm new to Javamail concept and i got the following exceptions when i tried to send a simple mail. First exception is : using java Could not connect to SMTP host:...
1
by: Ganeshb | last post by:
Hi all... When i call a click event written in serverside for a image button in a aspx page, the error displayed as below:... Invalid postback or callback argument. Event validation is...
2
aas4mis
by: aas4mis | last post by:
I have a query that works fine when ordered by the puller id (cf.op.id). The problem comes when I try to order by the sum of the boxes (sum(cf.qq)). I have read "UniVerse SQL Reference" and...
8
by: ahilar12 | last post by:
Hi experts, I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that...
5
by: najmi | last post by:
hai.. i hava use FullCalendar in my application.i try to reload event into the calendar but it doesn`t work.here is my code <%@ page import="java.util.HashMap;" %> <%@ page...
1
by: Prashant B | last post by:
I have a combo box on a form where i am having the list of fields from a table. Now I want to pass the selected field name to a query. Is it possible to do this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.