英文:
Use cast in order by clause JPQL
问题
在JPQL查询中,我想在ORDER BY子句中使用CAST运算符。该查询在SQL中有效,但应用程序在运行时产生了所示错误。如何在JPQL查询的ORDER BY子句中使用CAST?提前致谢。
@Query("SELECT a FROM tableA a WHERE a.tableB.ID = :ID ORDER BY CAST(col AS unsigned)")
错误信息:
Caused by: org.hibernate.QueryException: 无法解析所请求的CAST类型:unsigned:unsigned [SELECT r FROM classname a WHERE a.tableB.ID = :ID ORDER BY CAST(col AS unsigned)]
英文:
I have a JPQL query in which I want to use cast operator in the order by clause. The query works in SQL but the application gives the shown error at runtime. How to use cast in orderby clause in JPQL query? Thanks in advance.
@Query("SELECT a FROM tableA a where a.tableB.ID = :ID ORDER BY cast(col as unsigned)")
Error
Caused by: org.hibernate.QueryException: Could not resolve requested type for CAST : unsigned : unsigned [SELECT r FROM classname a where a.tableB.ID = :ID ORDER BY CAST(col as unsigned)]
答案1
得分: 1
我认为不支持无符号类型。interger
可能是最接近的选项。
@Query("SELECT a FROM tableA a WHERE a.tableB.ID = :ID ORDER BY CAST(col AS INTEGER)")
英文:
I think unsigned is not supported. interger
might be the closest.
@Query("SELECT a FROM tableA a where a.tableB.ID = :ID ORDER BY cast(col as integer)")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论