greenDAO update and updateInTx not working

1000 views Asked by At

I'm using greenDAO 3.1 for one of my projects. Since I needed my id to be UUID I've decided to store it as ByteArray. Now the problem is I can't update my entities using update or updateInTx method and I have to use insertOrReplace or insertOrReplaceInTx method.

Can anybody tell me what is going on and why can't I update using update methods?

Is there any downside to using insertOrReplace methods instead of update methods?

This is my Entity's schema code:

Entity book = schema.addEntity("Book");

book.addByteArrayProperty("id").columnName("_id").primaryKey();
book.addStringProperty("title");
book.addByteProperty("edition");
book.addStringProperty("authors");
book.addStringProperty("desc");
book.addStringProperty("pic");

And here's my update code:

BookDao bookDao = daoSession.getBookDao();

List<Book> books = bookDao.loadAll();
for (Book book : books)
    book.setDesc("It doesn't really matter!");

bookDao.updateInTx(books); //This isn't working
1

There are 1 answers

0
BehzadBx On BEST ANSWER

After a lot of searching and trouble I found the reason.

Since you can't query BLOB type in sqlite and since update methods use a condition over id in WHERE clause, the update method won't find the record I'm looking for. On the other hand when I use one of insertOrReplace methods, since the id field is unique it can't insert redundant id to the table and it completely replaces the old record with the one I'm trying to update. So, there was no problem with update methods, the real problem is with using ByteArray as id.

For the same reason, I also encountered an error when selecting using load method.