how to write order by and limit query in jpa [duplicate]
来源:互联网 发布:苹果bt下载软件 编辑:程序博客网 时间:2024/05/18 01:22
原址:点击打开链接
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 vote
limit
is not recognized in JPA. You can instead use the query.setMaxResults
method:
sm = em.createQuery("select m from MasterScrip m where m.type = :type order by m.totalTradedVolume") .setParameter("type", type) .setMaxResults(2).getResultList()
0 0
- how to write order by and limit query in jpa [duplicate]
- How To Look At MySQL Joins and More ORDER BY With LIMIT
- how to write and run jpa idempotent on mysql
- how to select data in multiple datatables after using join,group by and order by in Linq
- MySQL ORDER BY With LIMIT and ANALYZE
- CRM 4.0: How to Write and Deploy a Plug-In
- How to read and write JSON files in Java(Gson)
- How to show query plan and runtime statistic in Derby
- how to display value and text in query(query显示值和文本)
- How to Clean Up Duplicate Objects Owned by SYS and SYSTEM Schema (Doc ID 1030426.6)
- mysql order by limit
- order by/limit 注入
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- Linux tip - How to create a file and write by script?
- 如何使用MySQL Joins and More ORDER BY With LIMIT
- how to write it in C++?
- How to write paper in academic conference
- HTML 特殊符号编码对照表
- B-tree/B+tree/B*tree
- Android WebView页面加载优化
- Spring的AOP使用xml配置
- 324. Wiggle Sort II
- how to write order by and limit query in jpa [duplicate]
- PE文件结构分析
- Android官方开发文档Training系列课程中文版:构建第一款安卓应用之启动另一个Activity
- springmvc No mapping found for HTTP request with URI 可能原因统计
- 给Java说句公道话
- linux命令实用命令
- 152. Maximum Product Subarray
- Python 能干什么(一)
- escape()、encodeURI()、encodeURIComponent()区别详解
limit
is specific to some databasese (mysql) butHQL
is targetted to work with all the hibernate supported database.