产品
@DatabaseTable
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
public Product() {
// TODO Auto-generated constructor stub
}
public Product(String originalId) {
this.originalId = originalId;
}
@DatabaseField(id = true)
private String originalId;
...
@DatabaseField
private List<SkuInfo> skusInfo;
SkuInfo
public class SkuInfo implements Serializable {
private static final long serialVersionUID = 1L;
...
}
错误是:
java.lang.IllegalArgumentException: ORMLite does not know how to store interface java.util.List for field skusInfo. Use another class or a custom persister.
我用的时候:
@DatabaseField(dataType = DataType.SERIALIZABLE)
private List<SkuInfo> skusInfo;
错误更改为:
java.lang.IllegalArgumentException: ORMLite does not know how to store interface java.util.List for field skusInfo. Use another class or a custom persister.
我已经阅读了另外一篇关于标签Foreign的帖子,但我的项目不是外键。
答案 0 :(得分:1)
我使用了像发布here这样的自定义序列化对象并且工作了。
public class SerializableCollectionsType extends SerializableType {
private static SerializableCollectionsType singleton;
public SerializableCollectionsType() {
super(SqlType.SERIALIZABLE, new Class<?>[0]);
}
public static SerializableCollectionsType getSingleton() {
if (singleton == null) {
singleton = new SerializableCollectionsType();
}
return singleton;
}
@Override
public boolean isValidForField(Field field) {
return Collection.class.isAssignableFrom(field.getType());
}
}
产品
@DatabaseField(persisterClass = SerializableCollectionsType.class)
private List<SkuInfo> skusInfo;
答案 1 :(得分:0)
java.lang.IllegalArgumentException: ORMLite does not know how to store interface java.util.List for field skusInfo. Use another class or a custom persister.
仅仅为了后代,您可以将其更改为ArrayList
实际上实现java.io.Serializable
,因为它正在寻找它。不幸的是,List
并非如此,ORMLite会抛出异常。