In my Android project, ORMLite is functioning as a cache. I'm downloading data from a web server and placing it in the database. I'm calling createOrUpdate
on my objects, but duplicates are appearing in the database. The database entries are identical except for the primary key (which is simply an auto incremented integer). I think that since my second object doesn't yet have a primary key, ORMLite considers the two as being different, even though every other field is identical.
Does anyone know if this is true?
set your primary key for it to work normally.
@DatabaseField(columnName = "id",uniqueIndex = true) private int id;
Worked for me. Exceptions are thrown at background but it works :D
You should not be calling
createOrUpdate
unless your object already has an id field set. The wayORMLite
determines whether or not it exists in the database is to do a query-by-id on it. The code does:I'll expand the javadocs to explain this better. They are very weak there. Sorry. I've updated them to be:
It seems like you manually need to extract the id of the already existing entry and then
update
the database, based on your actual unique identifier. Example with unique URLs: