persistence@glassfish.java.net

Can you pass parameters to an Order By clause in NamedQuery?

From: Romanowski, Tim <tim.romanowski_at_lmco.com>
Date: Tue, 09 Jan 2007 00:07:05 -0500

Is it possible to create a named query that uses parameters in the
"order by" clause? When I include the following named query in an
entity, it throws the exception below. The exception occurs as soon as
I deploy my webapp; I only declare the namedquery, I do not use it
anywhere, so this is the point of failure. The reason I want to do this
is so that I can have sortable columns in my JSF app's datatables...if
there is a more efficient way to do this, I'd be interested in
suggestions!

 

@NamedQuery(name = "Task.findAllOrderByField", query = "SELECT t FROM
Task t ORDER BY :sortField :sortOrder")

 

Exception [TOPLINK-8024] (Oracle TopLink Essentials - 9.1 (Build b23)):
oracle.toplink.essentials.exceptions.EJBQLException Exception
Description: Syntax error parsing the query [SELECT t FROM Task t ORDER
BY :sortField :sortOrder] at [:sortField]. Internal Exception: line
1:31: expecting IDENT, found ':sortField'

 

 

Tim