1

我想我的類映射到使用ORMLite SQLite數據庫和我有麻煩來存儲字符串的集合,我有此錯誤:如何原始型(String)的集合存儲到數據庫

java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in 
    class java.lang.String 

這個錯誤是不言自明的,但我如何存儲字符串集合,我應該擴展字符串類並添加所需的註釋才能做到這一點? 在字段的註釋中我添加了datatype.serializable,但這也行不通。 這裏是我的課堂,我的問題:

@DatabaseTable(tableName = "parameters") 

public class Parameters { 

    // id is generated by the database and set on the object automagically 
    @DatabaseField(generatedId = true) 
    int id_parameters; 

    @DatabaseField(canBeNull = true) 
    @JsonProperty("id") 
    private Integer id; 

    @DatabaseField(canBeNull = false) 
    @JsonProperty("account_id") 
    private Integer account_id; 

    @ForeignCollectionField 
    @JsonProperty("languages") 
    private Collection<String> languages; 
    ... 
} 

領域的問題是語言!

回答

4

是的,你不能只是做一個字符串的集合。您將需要它來創建一個String領域的包裝類以及外國Parameters場:

public class Language { 
    @DatabaseField(generatedId = true) 
    int id; 
    @DatabaseField 
    String language; 
    @DatabaseField(foreign = true) 
    Parameters parameters; 
} 

這裏從FM年代description of foreign collections。引述:

請記住,當你有一個ForeignCollection場,集合中的類必須(在這個例子中階)必須有一個洋場爲具有集合(在這個例子賬戶)類。如果賬戶擁有外國訂單集合,則訂單必須有一個賬戶外國字段。 ORMLite可以找到與特定賬戶相匹配的訂單。

+0

感謝您清除此問題! – 2013-04-24 21:28:12

相關問題