I have problems mapping a Collection of Strings and Enums in my entities. I have followed different advices, but nothing seem to work. I am using PlayFramework 2.0 and the provided Ebean as ORM.
Here 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 generated DDL when the application is started looks like this:
create table foo (
id bigint not null,
constraint pk_foo primary key (id))
;
I would expect to see both the tables bar_foobar
and bar_strings
being created, if the annotations were correct.
If using the arrayOfString
variable, I get a weired error-message upon application launch (which related to a random entity, not necessarily Foo.class
PersistenceException: Error with [models.user.User] It has not been enhanced but it's superClass [class play.db.ebean.Model] is? (You are not allowed to mix enhancement in a single inheritance hierarchy) marker[play.db.ebean.Model] className[models.user.User]
I know I could wrap my Strings and Enums in entities, and use a @ManyToMany relationship, but the thought of it makes me shiver. Is there a bug here in Play 2.0 or Ebean (using v2.7.3)? Are there other ways I could solve my problem?