Android ORMLite, query by Serializable object

676 Views Asked by At

I use ORMLite and now have got a question that I can not answer. Look at my example : I have class implementes Serializable.

class Time implements Serializable {

private long time;

...blabla

}

and class Operation that includes Time

class Operation implements Serializable {

private Time time;

...blabla

}

Operation is a database table but Time not. As I think Time stored in database as byte array because it is Serializable Object. The question is it right to use ORMLite query like eq(), between() and other like that :

OperationDao.queryBuilder().where().between("time_field", timeObject1, timeObject2);

I am interested in : How does it work? Can I do queries like this and how? Or it is impossible, because Time is byte array and can not be used for query?

Thanks for good answers.

1

There are 1 best solutions below

2
On BEST ANSWER

The question is it right to use ORMLite query like eq(), between() and other like that ...

The short answer is no, you can't query for fields that are stored in the database as Serializable. I would recommend instead to use a Joda DateTime which gets stored in the database as a long. You will need to specify the @DatabaseField(dataType = DATE_TIME) because ORMLite works with DateTime using reflection. See the DateTimeType.