我怎样才能手工填写国外集合 [英] How can I fill the foreign collection manually

查看:256
本文介绍了我怎样才能手工填写国外集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

  @ForeignCollectionField(渴望= FALSE)
私人ForeignCollection<外勤及GT; fieldCollection;

和我想是因为我想这个数据插入到我的SQLite数据库,以填补因数据网络服务来此集合。

我试图用这样的:

 布尔accessOn premiseDb = FALSE;
字符串描述;@ForeignCollectionField(渴望= FALSE)
私人ForeignCollection<实体GT; entitiyCollection =
     新LazyForeignCollection<实体,整数GT;(NULL,accessOn premiseDb,
          accessOn premiseDb,空,说明,accessOn premiseDb);

但我得到了错误

 产生的原因:java.lang.IllegalStateException:内部DAO对象为null。
   如果它们已被反序列化,不能使用懒惰集合。

我怎么能这样做没有问题?我应该让新的变量呢?


解决方案

  

...我想是因为我想这个数据插入到我的SQLite数据库,以填补因数据网络服务来此集合。


右键。序列化错误消息是误导。您正在试图建立一个外国收集和你不能直接调用构造函数。你应该改为调用

  dao.assignEmptyForeignCollection(数据,entitiyCollection);

  data.entitiyCollection = dao.getEmptyForeignCollection(entitiyCollection);

这电线适当的DAO对象投向了国外收藏。我已经改善的javadoc和错误消息。


  

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


I have:

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

and I want to fill this collection from data coming from web service because I want to insert this data to my Sqlite database.

I tried to use this:

boolean accessOnPremiseDb = false;
String description;

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

but I got the error

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

How can I do that without problem? Should I make new variable for this?

解决方案

... I want to fill this collection from data coming from web service because I want to insert this data to my Sqlite database.

Right. The serialization error message is misleading. You are trying to create a foreign collection and you can't call the constructor directly. You should instead be calling

dao.assignEmptyForeignCollection(data, "entitiyCollection");

or

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

This wires the appropriate DAO object into the foreign collection. I've improved the javadocs and the error message.

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

这篇关于我怎样才能手工填写国外集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆