我在我的应用程序中使用ormlite android,我有一个表,其中有一列可以存储三种类型的数据,这些数据实际上是三个不同类的对象。我想在我的pojo类中声明该字段的数据类型,我也尝试使用对象,但仍然显示错误。Ormlite 不理解对象数据类型。
ormlite 是否提供对此类功能的支持?
编辑1
这是我的pojo类
@DatabaseTable(tableName = "itinerary_item")
public class ItineraryItem {
@DatabaseField(columnName = "id", id = true)
private int mId;
@DatabaseField(dataType = DataType.SERIALIZABLE, columnName = "item_type", foreign = true, foreignAutoRefresh = true)
private Object mItem;
,其中这个mitem可以是数据库中3种不同的类型,这基本上是三个不同POJO类的对象。
但我的问题是 ORMLite 不支持对象数据类型。
I am using ormlite android in my app and i have a table which have a column which can store three type of data which are actually the object of three different class.I want to declare data type of that field in my pojo class and i also tried with Object but still it is showing error.Ormlite does not understand Object data type.
Does ormlite provide any support for such functionality?
Edit 1
This is my pojo class
@DatabaseTable(tableName = "itinerary_item")
public class ItineraryItem {
@DatabaseField(columnName = "id", id = true)
private int mId;
@DatabaseField(dataType = DataType.SERIALIZABLE, columnName = "item_type", foreign = true, foreignAutoRefresh = true)
private Object mItem;
Where this mitem can be of 3 different Type in the database which is basically the object of three different POJO class.
But my problem is that ORMLite is not supporting the Object data type.
发布评论
评论(1)
请提供您尝试保留的对象的代码示例,并列出 完整异常>ORMLite 正在抛出。
但与此同时,我可以谈谈 ORMLite 可以保留哪些类型。这是完整列表:
它将检测各种字段类型。对于列表中特定的对象,ORMLite 还支持实现
Serialized
的持久对象。对于这些,您必须使用@DatabaseField(dataType = DataType.SERIALIZABLE)
专门声明类型。最后,对于高级用户,您可以定义并注册您 带有
@DatabaseField(persisterClass = ....class)
代码的自己的持久化类。编辑:
我建议如果
mitem
是 3 种类型之一,那么您有 3 个单独的字段,每个字段都有一个明确的类型 - 不要使用Object.然后,对于 pojo 类的每个实例,将设置 3 个字段中的 1 个,其他字段将为空。
Please provide a sample of code from the object you are trying to persist and please list the full exception that ORMLite is throwing.
But in the meantime I can talk a bit about what types ORMLite can persist. Here's the full list:
It will detect the various fields types. For objects that are specifically on the list, ORMLite also supports persisting objects that implement
Serializable
. For these you have to specifically declare the type with@DatabaseField(dataType = DataType.SERIALIZABLE)
.Lastly, for advanced users, you can define and register your own persister class with the
@DatabaseField(persisterClass = ....class)
code.Edit:
I would suggest if
mitem
is one of 3 types then you have 3 separate fields, each with a definitive type -- don't useObject
. Then for every instance of your pojo class, 1 of the 3 fields will be set and the others will be null.