1

我有:

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

我想从来自 Web 服务的数据中填充这个集合,因为我想将此数据插入到我的 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.

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

4

1 回答 1

4

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

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

dao.assignEmptyForeignCollection(data, "entitiyCollection");

或者

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

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

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

于 2014-01-03T15:39:18.343 回答