gpt4 book ai didi

java - ORMLite 初始化外部集合

转载 作者:搜寻专家 更新时间:2023-11-01 02:45:07 25 4
gpt4 key购买 nike

我的对象上有外部集合字段。如果我创建对象 > 保存它 > 查询它:那么我就拥有它并且可以使用它。但是,如果我创建对象并立即尝试访问外部集合字段,那么它就是空的。我该如何初始化它?

最佳答案

作为 ORMLite 的一部分Dao类,有一个assignEmptyForeignCollection(...) method .这会为您创建一个空集合并将其分配给适当的字段。

引用自Javadocs for the method :

Creates an empty collection and assigns it to the appropriate field in the parent object. This allows you to add things to the collection from the start. For example let's say you have an Account which has the field:

关于java - ORMLite 初始化外部集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24328814/

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