2012-05-10 31 views
0

我想在實體中添加一個額外的集合。但是,Ebean似乎沒有處理它,並且在我閱讀它時總是讓我感到空虛。如何在ebean實體中保存HashSet?

@Entity 
public class MyData extends Model { 
    @ElementCollection 
    public Set<String> extra = new HashSet<String>(); 
} 

回答

1

Ebean僅支持JPA 1.0並添加了一些模式註釋,如@PrivateOwned。不幸的是@ElementCollection尚未(Ebean 2.8.x)支持,並有一票這個問題http://www.avaje.org/bugdetail-378.html

你今天可以做的唯一的事情就是創建字符串實體的表(使用字符串字段和ID的實體)或者如果該集合不太大,則將這些字符串自己扁平化爲單個字符串。

public String extra; 

public Set<String> getExtra() { 
    // Split the string along the semicolons and create the set from the resulting array 
    return new HashSet<String>(Arrays.asList(extra.split(";"))); 
} 

public void setExtra(Set<String> extra) { 
    // Join the strings into a semicolon separated string 
    this.extra = Joiner.on(";").join(extra); 
} 
相關問題