java – 用Ebean映射String和枚举的集合(Play 2.0)
|
在我的实体中映射字符串和枚举集合时遇到问题.我遵循不同的建议,但似乎没有任何效果.我正在使用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
我知道我可以将我的字符串和枚举包装在实体中,并使用@ManyToMany关系,但是它的想法让我颤抖.在Play 2.0或Ebean中是否有错误(使用v2.7.3)?还有其他方法可以解决我的问题吗? 解决方法
在Ebean中还没有实现集合映射.
EBEAN-378您可以做的是自己实现映射.可以在Foo端使用@PrivateOwned注释,以确保如果字符串从集合中删除,则不会保留在数据库中.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
