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
After a lot of searching and trouble I found the reason.
Since you can't query
BLOB
type insqlite
and sinceupdate
methods use a condition overid
inWHERE
clause, theupdate
method won't find the record I'm looking for. On the other hand when I use one ofinsertOrReplace
methods, since theid
field is unique it can't insert redundantid
to the table and it completely replaces the old record with the one I'm trying to update. So, there was no problem withupdate
methods, the real problem is with usingByteArray
asid
.For the same reason, I also encountered an error when selecting using
load
method.