ORMLite 不知道如何存储接口 java.util.List



产品

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

斯库信息

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 的帖子中读到,但我的项目不是外键。

我使用了一个自定义可序列化对象,就像发布在这里一样并工作。

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.lang.IllegalArgumentException: ORMLite does not know how to store interface java.util.List for field skusInfo. Use another class or a custom persister.

只是为了后代,你可以把它改成一个实际实现java.io.SerializableArrayList,因为这就是它正在寻找的。 不幸的是,List没有,所以 ORMLite 抛出异常。

最新更新