Java – use ebean to map a collection of strings and enumerations (play 2.0)
There was a problem mapping strings and enum collections in my entity I followed different advice, but it didn't seem to have any effect I am using playframework 2.0 and the provided ebean as orm
This is an illustration class:
package models; import java.util.*; import javax.persistence.*; import play.db.ebean.Model; @Entity @Table(name = "foo") public class Foo extends Model { private static final long serialVersionUID = 1L; private enum FooBar { FOO,BAR; } @Id public Long id; @ElementCollection @Enumerated(EnumType.STRING) @CollectionTable(name = "bar_foobar",joinColumns = @JoinColumn(name = "bar_id",referencedColumnName = "id")) @Column(name = "foobar") public List<FooBar> fooBars; @ElementCollection(targetClass = String.class) @CollectionTable(name = "bar_strings",joinColumns = @JoinColumn(name = "bar_id")) @Column(name = "string",nullable = false) public List<String> listOfStrings; @Basic public List<String> listOfStrings2; // Attempt to circumvent the issue,but this gives a strange error //public String[] arrayOfString; }
The DDL generated when the application starts is as follows:
create table foo ( id bigint not null,constraint pk_foo primary key (id)) ;
If the comments are correct, I want to see bar_ Foobar and bar_ Strings are created
If I use the arrayofstring variable, I get an invalid error message when the application starts (related to random entities, not necessarily foo. Class)
I know I can wrap my strings and enumerations in entities and use the @ manytomany relationship, but its idea makes me tremble Are there any errors in play 2.0 or ebean (using v2.7.3)? Is there any other way to solve my problem?
Solution
Collection mapping has not been implemented in ebean Ebean - 378 all you can do is implement the mapping yourself The @ privateowned annotation can be used on the foo side to ensure that if the string is deleted from the collection, it will not be retained in the database