Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GreenDAO: Entity is detached from DAO context

I use GreenDAO. But, throws this exception:

"de.greenrobot.dao.DaoException: Entity is detached from DAO context".

In the generated code, i find this code.

/** called by internal mechanisms, do not call yourself. */
public void __setDaoSession(DaoSession daoSession) {
    this.daoSession = daoSession;
    myDao = daoSession != null ? daoSession.getPeerGroupDao() : null;
}

Anyone know when the GreenDAO call it? Also, how to trigger it to call.

Thanks.

like image 464
King Wu Avatar asked Dec 30 '25 13:12

King Wu


1 Answers

I find solution.

The greenDAO call __setDaoSession internally when you call loadDeep and queryDeep. After calling these method, the one to many or one to one relation is built up. If you just use SQLiteDatabase to query your result, you just get your data but the relationship is not built up.

In detail, you can go this site

Thanks.

like image 101
King Wu Avatar answered Jan 02 '26 03:01

King Wu