Android ORMLite, query by Serializable object

≯℡__Kan透↙ 提交于 2019-12-13 08:24:08

问题


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:


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.



来源:https://stackoverflow.com/questions/26967755/android-ormlite-query-by-serializable-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!