我用hql查询并排序,代码如下String hql="from Product p order by p.id ?";
.....
session.createQuery(hql).setString(0, p.getOrder()).....;我的意思是想设置问号处的排序方式 desc/asc
总提示出错
 unexpected token: ? near line 1, column 48
说这里不能这么用,为什么啊!!!

解决方案 »

  1.   

    hql语法问题,String hql="from Product as p order by p.id "
      

  2.   

    String hql="from Product as p order by p.id";后面的问号去掉。
      

  3.   

    String hql="from Product as p order by p.id ?";
    .....
    session.createQuery(hql).setString(0, p.getOrder()).....;这样不能用?
      

  4.   

    你也不一定要用hql语句啊
    用sql不一样的
    session.createSQLQuery(hql).xxxxxxxxxxxx
      

  5.   

    对不能用,如果p.id是问号就能用,就是asc/desc的地方不能用