gpt4 book ai didi

java - 列表关系中的项目顺序

转载 作者:行者123 更新时间:2023-11-30 06:30:20 24 4
gpt4 key购买 nike

这可能非常简单,但我在 JPA 规范中找不到关于它的任何明确说明。如果我有一个没有 @OrderBy 注释的基于 List 的关系,例如:

@OneToMany
List<Child> children;

那么在 Java 中这个列表元素的顺序是什么?如果是多对多,这将是 Child 表中相应记录的顺序或中间表中条目的顺序似乎是合理的,但这是 JPA 提供程序的保证行为吗?

最佳答案

据我所知,规范不保证顺序。 @OrderBy如果您依赖于订单,这是要走的路。

编辑:引自 JPA 1.0 规范:

Portable applications should not expect the order of lists to be maintained across persistence contexts unless the OrderBy construct is used and the modifications to the list observe the specified ordering. The order is not otherwise persistent.

(第 19 页,脚注 [4])

关于java - 列表关系中的项目顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10529395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com