ScrollMode.FORWARD_ONLY
即使我在谷歌上搜索过,我也想非常确定一件事。 ScrollMode.FORWARD_ONLY
是否意味着我将按照结果在数据库中的顺序接收结果?
我有这样的想法:
Scroller<Integer> foundRecs = new Scroller<Integer>(query.scroll(ScrollMode.FORWARD_ONLY));
也许是一个愚蠢的问题......
Even I've searched on google I want to be very sure about a thing.
Does ScrollMode.FORWARD_ONLY
means that I will receive the results in the order they are in DB?
I have something like:
Scroller<Integer> foundRecs = new Scroller<Integer>(query.scroll(ScrollMode.FORWARD_ONLY));
Maybe is a stupid question...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个特定的 API 是 Hibernate,我不太了解它,但我猜它映射到
TYPE_FORWARD_ONLY
最后(以及 其文档 同意提及该常量)。如果是这种情况,则否:这不会影响商品的退货顺序。
它only意味着您只能遍历结果一次并且只能向前导航(不能向后)。
数据库实际上并没有存储数据的“顺序”,因为它们的表是集合(而不是列表)。如果您需要对结果进行某种排序,那么您需要将 ORDER BY 添加到您的 SQL(或您使用的任何查询系统中的等效项)。
That specific API is Hibernate, which I don't know too much about, but I guess it maps down to
TYPE_FORWARD_ONLY
in the end (and its documentation agrees by mentioning that constant).If that's the case, then no: this will not influence the order in which items are returned.
It only means that you can only traverse the result once and can only navigate forward (not backwards).
Databases don't really have an "order" in which they store data, because their tables are sets (not lists). If you need some order for your results, then you need to add an
ORDER BY
to your SQL (or the equivalent in whichever query system you use).您不能依赖数据库中数据的物理顺序。如果您仅查询单个表,这可能可以工作,但一旦使用联接就会失败。
如果您希望数据按特定顺序显示,则需要 ORDER BY 子句。
You cannot rely on the physical order of data in the database. This might work if you query only a single table, but will fail as soon as you are using joins.
If you want your data to appear in a specific order, you need an ORDER BY clause.