簡體   English   中英

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

[英]ORMLite does not know how to store interface 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拋出異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM