how to write order by and limit query in jpa [duplicate]
2016-03-22 10:43
531 查看
原址:点击打开链接
i wish to fetch top 10 results based on 'totalTradedVolume' filed of my table 'MasterScrip' when i write the following query:
i get the following exception :
something's wrong with my jpa query. can anyone pls correct me?
解决办法:
i wish to fetch top 10 results based on 'totalTradedVolume' filed of my table 'MasterScrip' when i write the following query:
Collection<MasterScrip> sm=null; sm=em.createQuery("select m from MasterScrip m where m.type = :type order by m.totalTradedVolume limit 2").setParameter("type", type).getResultList();
i get the following exception :
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing the query [select m from MasterScrip m where m.type = :type order by m.totalTradedVolume limit 2], line 1, column 78: unexpected token [limit]. Internal Exception: NoViableAltException(80@[])
something's wrong with my jpa query. can anyone pls correct me?
解决办法:
34down voteaccepted | limitis not recognized in JPA. You can instead use the query.setMaxResultsmethod: sm = em.createQuery("select m from MasterScrip m where m.type = :type order by m.totalTradedVolume") .setParameter("type", type) .setMaxResults(2).getResultList() |
limitis specific to some databasese (mysql) but HQLis targetted to work with all the hibernate supported database. |
相关文章推荐
- Android自动化测试(UiAutomator)简要介绍 - 萧瑟一笑的专栏 - 博客频道 - CSDN.NET
- Crank Storyboard Suite入门(一)
- 【LeetCode】60. Permutation Sequence
- 304. Range Sum Query 2D - Immutable
- 对iOS 9 新增的控件 UIStackView 官方文档的翻译 第四部分
- 187. Repeated DNA Sequences
- 60. Permutation Sequence
- 手机GUI自动化测试介绍 | 有道技术沙龙博客
- C#中怎么生成36位的GUID
- UIViewContentMode各类型效果
- iOS开发~UITableViewCell重用机制总结
- android UI进阶之实现listview的分页加载
- libraries for bitcode must be generated from Xcode Archive or Install build forARM7 解决办法
- DelayQueue 队列
- 《iOS Human Interface Guidelines》——Contact Add Button
- UIStepper
- SQL Interview Questions
- PHP基础之如何调试PHP程序(HBuilder)
- pywinauto首页、文档和下载 - GUI 自动化测试框架 - 开源中国社区
- 原生的强大DOM选择器querySelector