エンティティに余分なセットを入れたい。しかし、Ebeanではそれを処理していないようで、読むと常にnullになります。
@Entity
public class MyData extends Model {
@ElementCollection
public Set<String> extra = new HashSet<String>();
}
エンティティに余分なセットを入れたい。しかし、Ebeanではそれを処理していないようで、読むと常にnullになります。
@Entity
public class MyData extends Model {
@ElementCollection
public Set<String> extra = new HashSet<String>();
}
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);
}