【问题标题】:How can I fill the foreign collection manually如何手动填写国外收藏
【发布时间】:2013-12-27 15:13:17
【问题描述】:

我有:

@ForeignCollectionField(eager = false)
private ForeignCollection<Field> fieldCollection;

我想用来自网络服务的数据填充这个集合,因为我想把这个数据插入到我的 Sqlite 数据库中。

我试过用这个:

boolean accessOnPremiseDb = false;
String description;

@ForeignCollectionField(eager = false)
private ForeignCollection<Entity> entitiyCollection =
     new LazyForeignCollection<Entity, Integer>(null, accessOnPremiseDb, 
          accessOnPremiseDb, null, description, accessOnPremiseDb);

但我得到了错误

Caused by: java.lang.IllegalStateException: Internal DAO object is null.
   Lazy collections cannot be used if they have been deserialized.

我怎样才能毫无问题地做到这一点?我应该为此创建新变量吗?

【问题讨论】:

    标签: java android ormlite foreign-collection


    【解决方案1】:

    ...我想从来自网络服务的数据中填充这个集合,因为我想将此数据插入到我的 Sqlite 数据库中。

    没错。序列化错误消息具有误导性。您正在尝试创建一个外部集合,并且您不能直接调用构造函数。你应该打电话给

    dao.assignEmptyForeignCollection(data, "entitiyCollection");
    

    data.entitiyCollection = dao.getEmptyForeignCollection("entitiyCollection");
    

    这会将适当的 DAO 对象连接到外部集合中。我改进了 javadocs 和错误消息。

    https://github.com/j256/ormlite-core/commit/b4037999c21f45c426ce7a83bc759e3ec8335c61

    【讨论】:

    • 如果我使用 Collection 而不是 ForeignCollection 并使用 ArrayList 填充数据,我会有什么问题吗?
    • 是否有大规模创作?我对最终如何插入数据感到困惑......
    猜你喜欢
    • 2015-11-30
    • 1970-01-01
    • 2010-11-12
    • 2015-03-09
    • 2021-09-13
    • 2018-01-06
    • 2019-12-01
    • 2021-06-05
    • 1970-01-01
    相关资源
    最近更新 更多