I'm trying to create and fetch some data on an Android SQLite database.
When I add the data with create method, objects are correctly updated (the Long id is set). But then, when I fetch the data with queryAll method, objects are correctly returned except the id attribute which comes as null. I'm using DatabaseField tag with generatedId attribute set to true, just like the documentation says:
generatedId
Boolean whether the field is an auto-generated id field. Default is false. Only one field can have this set in a class. This tells the database to auto-generate a corresponding id for every row inserted. When an object with a generated-id is created using the Dao.create() method, the database will generate an id for the row which will be returned and set in the object by the create method. Some databases require sequences for generated ids in which case the sequence name will be auto-generated. To specify the name of the sequence use generatedIdSequence. Only one of this, id, and generatedIdSequence can be specified. See section Fields With generatedId.
There's my class:
@DatabaseTable(tableName = "LANGUAGE")
public class Language {
@DatabaseField(generatedId = true, columnName = "language_id")
private Long id;
@DatabaseField(columnName = "language_locale")
private String locale;
@DatabaseField(columnName = "language_active")
private boolean active;
@DatabaseField(columnName = "language_name")
private String name;
// getters and setters...
}
I'm inserting the data like this:
Language pt = new Language();
pt.setActive(true);
pt.setName("Português");
pt.setLocale("pt_PT");
dao.create(pt);
Language en = new Language();
en.setActive(true);
en.setName("English");
en.setLocale("en_EN");
dao.create(en);
// here, both pt and en have an id, 1 and 2, respectively
But when I execute
dao.queryForAll()
locale, active and name attributes comes ok, but id is null.
Any ideia? I already tried to call commit after create but nothing changes.