gpt4 book ai didi

java - jpa 返回哪些集合?

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

JPA(在本例中为 Eclipselink)是否总是在实体有列表的地方返回间接列表?那个列表可以吗,还是应该转换成另一个列表(也许是链表)?

最佳答案

分析

如果我们查看 EclipseLink 的 IndirectList's API ,它说:

To use an IndirectList: declare the appropriate instance variable with type IndirectList (jdk1.1) or Collection/List/Vector (jdk1.2).

TopLink will place an IndirectList in the instance variable when the containing domain object is read from the datatabase. With the first message sent to the IndirectList, the contents are fetched from the database and normal Collection/List/Vector behavior is resumed.

如果我们查看 IndirectList sources ,我们将看到,所有工作都委托(delegate)给它的原始集合,就像 API 所说的那样。

答案

Does JPA ( Eclipselink in this case) always return IndirectList where Entity have a List?

是的,它总是会返回用 IndirectList 包装的指定集合。由于它将所有内部工作委托(delegate)给包装的集合,因此它保留了它的工作方式。

Is ok that list or It should be converted to another list( maybe linkedlist)?

是的,使用IndirectList是可以的。您无需转换,只需定义您想要的任何类型的集合,不必担心 IndirectList,因为它是透明管理的。

关于java - jpa 返回哪些集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10972971/

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