0

i use GreenDao and create entries for a Category, which perfectly works. My problem is, when i repeat the action, it comes a failure with de.greenrobot.dao.DaoException: Entity is detached from DAO context. I looked in the database with SQLite Debugger and saw every time i insert these entries an entry in sqlite_sequence appeared. I deleted it manually with my app "SQLite Debugger". After this it works.

Now the question. How can i do this automatically?

CodeSnippet

if (category_CategoriesCompaniesQuery == null || category_CategoriesCompaniesQuery.equals(null)) {
        QueryBuilder<CategoryCompany> tempQueryBuilder = queryBuilder();
        tempQueryBuilder.where(Properties.CategoryID.eq(categoryID));
        category_CategoriesCompaniesQuery = tempQueryBuilder.build().forCurrentThread();
    } else {
        category_CategoriesCompaniesQuery.forCurrentThread().setParameter(0, categoryID);
    }
    return category_CategoriesCompaniesQuery.forCurrentThread().list();
}

Stacktrace

02-04 12:05:38.883: E/AndroidRuntime(23568): java.lang.RuntimeException: An error occured while executing doInBackground() 02-04 12:05:38.883: E/AndroidRuntime(23568): at android.os.AsyncTask$3.done(AsyncTask.java:300) 02-04 12:05:38.883: E/AndroidRuntime(23568): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) 02-04 12:05:38.883: E/AndroidRuntime(23568): at java.util.concurrent.FutureTask.setException(FutureTask.java:222) 02-04 12:05:38.883: E/AndroidRuntime(23568): at java.util.concurrent.FutureTask.run(FutureTask.java:242) 02-04 12:05:38.883: E/AndroidRuntime(23568): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 02-04 12:05:38.883: E/AndroidRuntime(23568): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 02-04 12:05:38.883: E/AndroidRuntime(23568): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 02-04 12:05:38.883: E/AndroidRuntime(23568): at java.lang.Thread.run(Thread.java:841) 02-04 12:05:38.883: E/AndroidRuntime(23568): Caused by: de.greenrobot.dao.DaoException: Entity is detached from DAO context 02-04 12:05:38.883: E/AndroidRuntime(23568): at com.adamasvision.mytermin.model.Category.getCategoriesCompanies(Category.java:152) 02-04 12:05:38.883: E/AndroidRuntime(23568): at com.adamasvision.mytermin.UserState$1.doInBackground(UserState.java:415) 02-04 12:05:38.883: E/AndroidRuntime(23568): at com.adamasvision.mytermin.UserState$1.doInBackground(UserState.java:1) 02-04 12:05:38.883: E/AndroidRuntime(23568): at android.os.AsyncTask$2.call(AsyncTask.java:288) 02-04 12:05:38.883: E/AndroidRuntime(23568): at java.util.concurrent.FutureTask.run(FutureTask.java:237)

Logi24
  • 528
  • 6
  • 17

1 Answers1

0

sqlite_sequence keeps track of autoincrement values. You should not mess with it, because it will probably destroy your dataintegrity.

AlexS
  • 5,295
  • 3
  • 38
  • 54
  • Yeah i know it down't help to delete it automatically because the seperate app closes the background tasks of my app and by my automatic deleting i don't want to do this. I searched a bit [and found here a possible answer](http://stackoverflow.com/questions/15611564/greendao-entity-is-detached-from-dao-context). I have to use "loadDeep" and "queryDeep", but i don't know how to use it. Do you know it or can you help me? – Logi24 Feb 04 '14 at 11:16