I want to put an extra set in an entity. But with Ebean seems to not handle it and always gives me null when I read it.
@Entity
public class MyData extends Model {
@ElementCollection
public Set<String> extra = new HashSet<String>();
}
I want to put an extra set in an entity. But with Ebean seems to not handle it and always gives me null when I read it.
@Entity
public class MyData extends Model {
@ElementCollection
public Set<String> extra = new HashSet<String>();
}
Ebean supports only JPA 1.0 and adds a few mode annotations like @PrivateOwned. Unfortunately @ElementCollection
is not supported yet (Ebean 2.8.x) and there is a ticket for this issue http://www.avaje.org/bugdetail-378.html
The only thing you can do today is create a table of String entities (an entity with a string field and an ID) or flatten the strings yourself into a single string if the set is not too big.
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);
}