我正在使用 ORMLite,尝试使用foreignCollectionKey,但出现以下错误:
内部 DAO 对象为空。如果 LazyCollections 已被反序列化,则无法使用它们。
我的对象名为 Zone :
public class Zone implements Serializable {
private static final long serialVersionUID = 1L;
public static final String ZONE_ID = "id";
public static final String ZONE_PARENT_ID = "parentZoneId";
@DatabaseField(generatedId=true)
private int id;
@DatabaseField()
String name;
@DatabaseField(foreign=true, foreignAutoRefresh = true)
Zone parentZone;
@ForeignCollectionField(foreignFieldName = "parentZone", eager = true)
private ForeignCollection<Zone> zoneChild;
public Zone() {
// TODO Auto-generated constructor stub
}
public ForeignCollection<Zone> getZoneChild() {
return zoneChild;
}
public void setZoneChild(ForeignCollection<Zone> zoneChild) {
this.zoneChild = zoneChild;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
在类中,我正在执行递归方法来获取所有区域子对象:
public void getZone(Zone zone, Dao<Zone, Integer> tempZoneDao){
ZoneListEntity zoneEntity = new ZoneListEntity();
zoneEntity.setName(zone.getName());
zoneEntity.setNiveau(0);
zoneEntity.setZone(zone);
mainZoneList.add(zoneEntity);
List<Zone> childList = new ArrayList<Zone>(zone.getZoneChild());
//set rootZone's children as ZoneListEntity
for(Zone currentZone : childList){
ZoneListEntity zoneGroup = new ZoneListEntity();
zoneGroup.setName(currentZone.getName());
zoneGroup.setZone(currentZone);
System.out.println("Zone : "+currentZone.getName());
getZone(currentZone, tempZoneDao);
}
}
当我第一次进入我的getZone
,一切顺利。然后当我循环时getZone
应用程序在尝试访问子区域时崩溃:
List<Zone> childList = new ArrayList<Zone>(zone.getZoneChild());
你有什么想法 ?我的模型构造正确吗?
谢谢
你有什么想法 ?我的模型构造正确吗?谢谢
所以异常消息试图解释发生了什么。我不确定如何改进。
内部 DAO 对象为空。如果 LazyCollections 已被反序列化,则无法使用它们。
您正在尝试访问zoneChild
这是一个ForeignCollection
已被反序列化。由于它已被反序列化,因此无法重新建立所有底层数据库配置和连接。我猜当它存储在 Android 中时可能会发生这种情况Bundle
?我不确定这是否是唯一的情况。
如果您需要获得Zone
你必须打电话给孩子dao.refresh()
在实体上after您反序列化它或通过执行以下操作自己进行查询zoneDao
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)