Hibernate命名查询顺序按参数 [英] Hibernate Named Query Order By parameter
本文介绍了Hibernate命名查询顺序按参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
例如:
Works:
从TransportBooking中选择tb作为tb
和TIMESTAMP(tb.bookingDate ,tb.bookingTime)> = current_timestamp()order by tb.bookingDate
不起作用:
从TransportBooking中选择tb作为tb
和TIMESTAMP(tb.bookingDate,tb.bookingTime)> = current_timestamp()order by:order
解决方案
不支持,输入参数只允许在 WHERE
和 HAVING
子句中使用,您不能使用 ORDER BY
子句。或者,如果我改述,你不能使用列的参数,只能使用值。所以,要么:
- 尽可能多地命名查询以排序顺序
- 连接排序字符串查询字符串
- 使用条件查询
Hi can anyone point me to how we can pass an order by clause as named parameter to hql
Ex:
Works:
select tb from TransportBooking as tb
and TIMESTAMP(tb.bookingDate, tb.bookingTime) >= current_timestamp() order by tb.bookingDate
Does not work:
select tb from TransportBooking as tb
and TIMESTAMP(tb.bookingDate, tb.bookingTime) >= current_timestamp() order by :order
解决方案
Not supported, input parameters are only allowed in the WHERE
and HAVING
clauses and you cannot use parameters for the ORDER BY
clause. Or if I rephrase, you can't use parameters for columns, only values. So, either:
- Have as much named queries as possible sort orders
- Concatenate the ordering string to the query string
- Use criteria queries
这篇关于Hibernate命名查询顺序按参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文