I have this object:
public class Set {
@DatabaseField(columnName = "setID", generatedId = true)
private int setID;
@DatabaseField(columnName = "setName")
private String setName;
}
If I make an object like this:
Set newSet = new Set("name");
setDao.create(newSet);
And then if i make this:
int id = newSet.getID();
Will I get the set id or should I get the whole object from the database with
setDao.queryForEq("setName", "name");
So the ORMLite documentation is pretty extensive. If you look up generated-id in the docs you'd see the following statement:
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.
So after you call setDao.create(newSet)
, the newSet
object's setID
field will be changed with the id from the database.
Also, calling a field setID
is a very bad pattern. I'd recommend just use id
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With