2012-05-10 9 views
0

エンティティに余分なセットを入れたいと思います。しかし、Ebeanはそれを処理していないようで、私はそれを読むと常に私にnullを与えます。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

あなたが今日行うことができる唯一のことは、Stringエンティティ(文字列フィールドを持つエンティティとID)のテーブルを作成することですセットが大きすぎない場合は、文字列を1つの文字列にまとめることができます。

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); 
} 
関連する問題