gpt4 book ai didi

java - ORMLite 不知道如何存储接口(interface) java.util.List

转载 作者:行者123 更新时间:2023-12-01 10:23:19 26 4
gpt4 key购买 nike

产品

@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;

Sku信息

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”的文章中读到过,但我的项目不是外键。

最佳答案

我使用了自定义可序列化对象,如发布的 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;

关于java - ORMLite 不知道如何存储接口(interface) java.util.List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35459599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com