I am using HQL to create some dynamic querries....having trouble with the order by clause.
If I build the oder by clasue in my query string excplicitly as in :
Code:
qryStr = qryStr + " ORDER BY lower(metric_description) desc";
all is well. If, instead, I use a named replacement variable...the result set is not ordered:
Code:
qryStr = qryStr + " ORDER BY :orderByField asc";
query.setString("orderByField","metric_description");
No error is thrown, the results simply are not ordered. I've tried numerous variations on the theme, but the only thing that works is building the order by into my string (no substitutions) myself. I use the named substitutions in the query in my where clause and that works fine.
Lee
-------------------------------------------------------------
Hibernate version: Not sure how to tell, I do see a "hibernate2.jar"
Mapping documents: NA
Code between sessionFactory.openSession() and session.close(): NA
Full stack trace of any exception that occurs: NA
Name and version of the database you are using: Oracle 9i
The generated SQL (show_sql=true):
Hibernate: select nddmetric0_.METRIC_ID as METRIC_ID, nddmetric0_.REPORT_OWNER_NAME as REPORT_O2_, nddmetric0_.SHORT_NAME as SHORT_NAME, nddmetric0_.REPORT_OWNER_ID as REPORT_O4_, nddmetric0_.REPORT_NAME as REPORT_N5_, nddmetric0_.REPORT_ID as REPORT_ID, nddmetric0_.LOGIC_DESCRIPTION as LOGIC_DE7_, nddmetric0_.LOGIC_SHORT_DESC as LOGIC_SH8_, nddmetric0_.LOGIC_ORDER as LOGIC_OR9_, nddmetric0_.LOGIC_ID as LOGIC_ID, nddmetric0_.MODULE_NAME as MODULE_11_, nddmetric0_.MODULE_TYPE as MODULE_12_, nddmetric0_.MODULE_DESCRIPTION as MODULE_13_, nddmetric0_.MODULE_ID as MODULE_ID, nddmetric0_.TABLE_NAME as TABLE_NAME, nddmetric0_.TABLE_ID as TABLE_ID, nddmetric0_.DATABASE_NAME as DATABAS17_, nddmetric0_.DATABASE_ID as DATABAS18_, nddmetric0_.DATA_STORE_NAME as DATA_ST19_, nddmetric0_.DATA_STORE_DESCRIPTION as DATA_ST20_, nddmetric0_.DATA_STORE_LINK as DATA_ST21_, nddmetric0_.CONTACT_PHONE as CONTACT22_, nddmetric0_.CONTACT_NAME as CONTACT23_, nddmetric0_.DATA_STORE_ID as DATA_ST24_, nddmetric0_.FUNCTIONAL_AREA_NAME as FUNCTIO25_, nddmetric0_.FUNCTIONAL_AREA_DESCRIPTION as FUNCTIO26_, nddmetric0_.FUNCTIONAL_AREA_SHORT_NAME as FUNCTIO27_, nddmetric0_.FUNCTIONAL_AREA_ID as FUNCTIO28_, nddmetric0_.LAST_MOD_BY as LAST_MO29_, nddmetric0_.LAST_MOD_DATE as LAST_MO30_, nddmetric0_.METRIC_ID as METRIC_ID, nddmetric0_.METRIC_NAME as METRIC_31_, nddmetric0_.METRIC_DESCRIPTION as METRIC_32_, nddmetric0_.METRIC_NUMBER as METRIC_33_, nddmetric0_.DATA_STEWARD as DATA_ST34_ from NDD_METRIC nddmetric0_ where (UPPER(metric_number)LIKE ? )OR(UPPER(metric_name)LIKE ? )OR(UPPER(metric_description)LIKE ? )OR(UPPER(functional_area_name)LIKE ? )OR(UPPER(table_name)LIKE ? )OR(UPPER(report_name)LIKE ? )OR(UPPER(report_owner_name)LIKE ? )OR(UPPER(data_store_name)LIKE ? )OR(UPPER(data_steward)LIKE ? )OR(UPPER(database_name)LIKE ? ) order by ? asc
Debug level Hibernate log excerpt: NA