DaoException: Entity is detached from DAO context

a 夏天 提交于 2019-12-05 07:56:33

Objects representing database entries (like User) are only attached to a Database-session if they have been fetched from the database or inserted to the database before.

It looks like you don't load your user-object using greendao, but instead just create it with new.

You also seem not to store this user-object using the dao. Thus the user-object is not attached to the session.

On top of that you are also just setting the userid in each store. If you haven't inserted the user-object somewhere else this may also cause an error since the foreignkey-constraint may be broken (depending on how greendao handles this internally).

Try to add the user-object to the stores with setUser() instead of setUserIdForStore().

If this doesn't work try to store or load the user-object first using a UserDao.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!