0

I use serialization but when I deserialize an object and I try to resolve a relation I catch this exception:

Entity is detached from DAO context

I think because the daoSession and myDao are transient and are nullified on serialization.

How can I reset daoSession and myDao safely?

1 Answers1

1

Why would you serialize an object when you have a database? Writing/reading to the DB is so much faster than serialization.

If you want to pass objects to another activity, just pass the id and load the object using greenDAO. This is superfast, because it's a map-look up most of the times.

If you really really need to do it this way, there's a not really officially supported method called __setDaoSession you could call after you deserialized your object. However, we don't guarantee that this method will exist forever.

Markus Junginger
  • 6,950
  • 31
  • 52
  • I have a class which is generated from json response. Now i wanna access a property which is managed by greenDAO but when i access i get the same exception. I query like `topic.owner()` – Cerlin Apr 25 '17 at 09:20