Hibernate 以及 setFirstResult 标准方法的使用
我正在尝试学习 hibernate criteria API,但我对 criteria 方法 setFirstResult 感到困惑。
我不明白为什么除了在最罕见的情况下我会想使用它。在我看来,当我从数据库检索信息时,我只对建立一些标准感兴趣,然后根据该标准执行查询。为什么我关心应该从数据库中的哪个索引号读取结果。这不是我在编写 sql 查询时通常会做的事情,但我在 hibernate 文献中看到了这种方法。我在编写 Hibernate 查询时是否总是必须调用此方法,或者我可以安全地忽略它吗?
谢谢你,
埃利奥特
I'm trying to learn the hibernate criteria API but I'm puzzled by the criteria method setFirstResult.
I don't understand why I would want to use it except in the rarest of circumstances. It seems to me that when I retrieve information from a database, I'm only interested in establishing some criteria and then executing the query against the criteria. Why do I care from which index number in the database the results should be read. It is not something I normally do when I write sql queries yet I see this method all over the hibernate literature. Is this method something I always have to invoke when writing Hibernate queries or can I safely ignore it?
Thank you,
Elliott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这通常在显示查询的分页结果时使用。第一页从 0 到 19,第二页从 20 到 39,依此类推。
This is typically used when displaying paginated results of a query. The first page goes from 0 to 19, the second page from 20 to 39, etc.
好吧,我在很多地方使用它......不幸的是,或者完全幸运/愚蠢的是,您遇到了需要对结果进行分页的情况,在这种情况下,您通常会正确地从一个索引选择到另一个索引的查询。考虑这样的情况:您想要显示为页面上的每个写入操作存储的应用程序的审核日志。在这种情况下,您将根据用户所在的页面以及审核日志排序的字段显示 20 个结果。
Well I use it in a bunch of places.. its unfortunate or outright lucky/dumb that you have run into a case where you needed to page your results in which case you generally right queries that pick from one index to another. consider the case where you want to display the audit log of an app that is stored for every write action on the page. in that case you will show the 20 results based on which page the user is and what field the audit log is sorted on.