DAO does not update the object

1,384 views
Skip to first unread message

Howard Liberty

unread,
Jan 5, 2012, 8:31:44 PM1/5/12
to ORMLite Android Users
I created some Dao without the object cache. The query is working well
but it seems like I can't update the dao. Please let me know if you
want more info.


Code:

.....
all = cardDao.queryForAll();
for (Card c : all) {
c.setQuestion("Hello");
cardDao.update(c);
}
all = cardDao.queryForAll();
for (Card c : all) {
System.out.println(c.getQuestion());
}


Here is the output from the log:

D/StatementExecutor(20103): query of 'SELECT * FROM `cards` ' returned
28 results
D/BaseMappedStatement(20103): update data with statement 'UPDATE
`cards` SET `answer` = ?, `cardType` = ?, `category_id` = ?, `creation
Date` = ?, `learningData_id` = ?, `note` = ?, `ordinal` = ?,
`question` = ?, `updateDate` = ? WHERE `id` = ? AND `updateDate` = ?'
and
11 args, changed 1 rows
....
D/BaseMappedStatement(20103): update data with statement 'UPDATE
`cards` SET `answer` = ?, `cardType` = ?, `category_id` = ?, `creation
Date` = ?, `learningData_id` = ?, `note` = ?, `ordinal` = ?,
`question` = ?, `updateDate` = ? WHERE `id` = ? AND `updateDate` = ?'
and
11 args, changed 1 rows
D/BaseMappedStatement(20103): update data with statement 'UPDATE
`cards` SET `answer` = ?, `cardType` = ?, `category_id` = ?, `creation
Date` = ?, `learningData_id` = ?, `note` = ?, `ordinal` = ?,
`question` = ?, `updateDate` = ? WHERE `id` = ? AND `updateDate` = ?'
and
11 args, changed 1 rows
D/BaseMappedStatement(20103): update data with statement 'UPDATE
`cards` SET `answer` = ?, `cardType` = ?, `category_id` = ?, `creation
Date` = ?, `learningData_id` = ?, `note` = ?, `ordinal` = ?,
`question` = ?, `updateDate` = ? WHERE `id` = ? AND `updateDate` = ?'
and
11 args, changed 1 rows
D/BaseMappedStatement(20103): update data with statement 'UPDATE
`cards` SET `answer` = ?, `cardType` = ?, `category_id` = ?, `creation
Date` = ?, `learningData_id` = ?, `note` = ?, `ordinal` = ?,
`question` = ?, `updateDate` = ? WHERE `id` = ? AND `updateDate` = ?'
and
11 args, changed 1 rows
D/BaseMappedStatement(20103): prepared statement 'SELECT * FROM
`cards` ' with 0 args
D/SelectIterator(20103): starting iterator @1081028416 for 'SELECT *
FROM `cards` '
D/SelectIterator(20103): closed iterator @1081028416 after 28 rows
D/StatementExecutor(20103): query of 'SELECT * FROM `cards` ' returned
28 results
I/System.out(20103): head
I/System.out(20103): hair
I/System.out(20103): face
I/System.out(20103): eye
I/System.out(20103): eyes
I/System.out(20103): nose
I/System.out(20103): cheek
I/System.out(20103): mouth
I/System.out(20103): lip
.......

Howard Liberty

unread,
Jan 5, 2012, 8:40:51 PM1/5/12
to ORMLite Android Users
Also forgot to say version 4.31

Howard Liberty

unread,
Jan 7, 2012, 9:41:30 PM1/7/12
to ORMLite Android Users
Seem like it is a problem when I manually create using raw update but
didn't provide a Date updateDate who has with "version=true".

Also
dao.update(new Card()) doesn't work but doesn't throw an exception or
error.

Gray Watson

unread,
Sep 5, 2012, 3:31:50 PM9/5/12
to ormlite...@googlegroups.com
On Jan 5, 2012, at 8:31 PM, Howard Liberty wrote:

> all = cardDao.queryForAll();
> for (Card c : all) {
> c.setQuestion("Hello");
> cardDao.update(c);
> }
> all = cardDao.queryForAll();
> for (Card c : all) {
> System.out.println(c.getQuestion());
> }

This code looks fine to me Liberty. Did you figure it out. Sorry for the delay in responding.

> D/BaseMappedStatement(20103): update data with statement 'UPDATE
> `cards` SET `answer` = ?, `cardType` = ?, `category_id` = ?, `creation
> Date` = ?, `learningData_id` = ?, `note` = ?, `ordinal` = ?,
> `question` = ?, `updateDate` = ? WHERE `id` = ? AND `updateDate` = ?'
> and
> 11 args, changed 1 rows

This looks like it changed 1 row at least. I wonder if this is a problem with the object cache? Are you using it?
gray

Hamid Palo

unread,
May 1, 2013, 1:55:56 PM5/1/13
to ormlite...@googlegroups.com
I have been noticing this a lot recently on Android with 4.44. With caching, the objects do not get updated despite the update saying it was successful  leading to stale data and headaches.

hp

Alan Neves

unread,
Dec 5, 2013, 2:50:01 PM12/5/13
to ormlite...@googlegroups.com
I've had the same problem. It was my version field. I've removed the annotation from the field and everything is working fine now !

Gray Watson

unread,
Dec 12, 2013, 6:30:34 PM12/12/13
to ormlite...@googlegroups.com
On Dec 5, 2013, at 2:50 PM, Alan Neves <alanc...@gmail.com> wrote:

> I've had the same problem. It was my version field. I've removed the annotation from the field and everything is working fine now !
> More info at: https://groups.google.com/forum/#!searchin/ormlite-android/update/ormlite-android/ayMjWnlkAJg/kS2jfm29a7gJ

The version=true field has specific semantics and is specifically for helping in distributed environments so that multiple copies of the same object on multiple boxes won't overwrite stale data.

See the docs: http://ormlite.com/docs/version-field

This means that if one part of the program updates and another part of your program has a stale copy of the data, an update to it won't work. It is designed to _not_ throw an exception but rather dao.update(...) will return 0 rows updated. Maybe that should be a setting on the DAO to throw instead?

There might be some problem with the object cache and the version field. If folks are having problems with this, can someone send me a small unit test that fails?

Thanks,
gray

Reply all
Reply to author
Forward
0 new messages