Android GreenDao 获取一对多内容实体时候报错:Entity is detached from DAO context 请问是什么原因?
发布时间:2018-02-01 来源:查字典编辑
摘要:功能:列表中选择分类,然后获取与该类别关联的对象List,添加到数据源中,再刷新ListView。de.greenrobot.dao.Dao...
功能: 列表中选择分类,然后获取与该类别关联的对象List,添加到数据源中,再刷新ListView。
de.greenrobot.dao.DaoException: Entity is detached from DAO context
在拿到自己1对多的实体内容的时候,会报出该异常。第一次是没问题的。
/** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */
public List< CasesFormInfo > getCasesFormInfoList() {
if (casesFormInfoList == null) {
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
CasesFormInfoDao targetDao = daoSession.getCasesFormInfoDao();
List< CasesFormInfo > casesFormInfoListNew = targetDao._queryCasesFormCategoryInfo_CasesFormInfoList(paramid);
synchronized (this) {
if(casesFormInfoList == null) {
casesFormInfoList = casesFormInfoListNew;
}
}
}
return casesFormInfoList;
} 求指点!感激不尽!
回复讨论(解决方案)
解决了吗?我最近在用,碰到同样的问题了