ScrollMode.FORWARD_ONLY

发布于 2024-11-04 15:58:43 字数 263 浏览 1 评论 0原文

即使我在谷歌上搜索过,我也想非常确定一件事。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羞稚 2024-11-11 15:58:43

这个特定的 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).

深空失忆 2024-11-11 15:58:43

您不能依赖数据库中数据的物理顺序。如果您仅查询单个表,这可能可以工作,但一旦使用联接就会失败。
如果您希望数据按特定顺序显示,则需要 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文