In my Android app, I've got the following class:
@DatabaseTable(tableName="things")
public class Thing {
public static final String ID_FIELD_NAME = "id";
public static final String FLOAT_FIELD_NAME = "myFloatField";
@DatabaseField(generatedId=true,columnName=ID_FIELD_NAME)
private int id;
@DatabaseField(columnName=FLOAT_FIELD_NAME)
private float myFloatField;
//[snip constructor and getters]
}
Then, in my DBManager, I do the following:
Dao<Thing, Integer> dao = helper.getThingDao();
Thing tmp = dao.queryBuilder()
.where()
.eq(Thing.FLOAT_FIELD_NAME, otherThing.getFloatField());
Turns out that evvery once in a while tmp
will be null
.
I tried many things and varied, and what I found to be working to get the right Thing
every time is the following:
Dao<Thing, Integer> dao = helper.getThingDao();
Thing tmp = dao.queryBuilder()
.where()
.eq(Thing.FLOAT_FIELD_NAME, Double.valueOf(otherThing.getFloatField()));
I read in the docs:
float or Float (DataType.FLOAT or DataType.FLOAT_OBJ) Persisted as SQL type FLOAT.
double or Double (DataType.DOUBLE or DataType.DOUBLE_OBJ) Persisted as SQL type DOUBLE.
So my question is:
is this a bug in my code (but I don't see how, am I not using that where()
correctly?), a weird thing ormlite has with float
s or something else entirely?
Edit: I'm using ormlite-core-4.48.jar and ormlite-android-4.48.jar.
Edit 2: what's more, if I change the field from float
to double
and then execute the query, it still doesn't work. I need to use Double.valueOf()
.