[jboss-user] [EJB 3.0] - Dynamic Named Query?

hotat27 do-not-reply at jboss.com
Thu Sep 7 01:33:05 EDT 2006


Hello,

Currently I'm using named query which is written in orm.xml and is working fine.

  | Query query = em.createNamedQuery("selectAddresses");
  | query.setParameter("postcode", 50000);
  | query.getResultList();
  | 
  | <query>
  | select * from address where postcode=:postcode ORDER BY state ASC
  | </query>
  | 
Is it possible to dynamically change the "ORDER BY state ASC" to ascending or descending in java code, either through query.setParameter("", "") or any other methods?

I've tried the setParameter method, for example

  | <query>select * from address where postcode=:postcode ORDER BY state :ordering</query>
  | 
  | query.setParameter("ordering", "ASC") or query.setParameter("ordering", "DESC")
  | 
but the result didn't seem to be consistent.

Thanks in advance.
Steven

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969960#3969960

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969960



More information about the jboss-user mailing list