在我的实体中映射字符串和枚举集合时遇到问题.我遵循不同的建议,但似乎没有任何效果.我正在使用PlayFramework 2.0和提供的Ebean作为ORM.
这是一个插图类:
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; }
应用程序启动时生成的DDL如下所示:
create table foo ( id bigint not null,constraint pk_foo primary key (id)) ;
如果注释正确,我希望看到bar_foobar和bar_strings都被创建.
如果使用arrayOfString变量,我在应用程序启动时得到一个无效的错误消息(与随机实体相关,不一定是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]
我知道我可以将我的字符串和枚举包装在实体中,并使用@ManyToMany关系,但是它的想法让我颤抖.在Play 2.0或Ebean中是否有错误(使用v2.7.3)?还有其他方法可以解决我的问题吗?