开发者

How to have 2 collections of the same type in JPA? (EclipseLink)

Wondering how to do what is specified in How to have 2 collections of the same type in JPA?, but with EclipseLink rather than Hibernate. See that post below:

I've got 2 entities in JPA: Entry and Comment. Entry contains two collections of Comment objects.

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@IndexColumn(base = 1, name = "dnr")
private List<Comment> descriptionComments = new ArrayList<Comment>();

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@IndexColumn(base = 1, name = "pmnr")
private List<Comment> postMortemComments = new ArrayList<Comment>();

To store such objects, JPA+Hibernate creates "Entry" table, "Comment" table and SINGLE "Entry_Comment":

create table Entry_Comment (Entry_id integer not null, postMortemComments_id integer not null, pmnr integer not null, descriptionComments_id integer not null, dnr integer not null开发者_JAVA百科, primary key (Entry_id, dnr), unique (descriptionComments_id), unique (postMortemComments_id))

Storing of objects fail as descriptionComments_id and postMortemComments_id cannot be "not null" at the same time.

How do I store object containing two collections of the same type using JPA+Hibernate?

I am sure it is pretty simple to convert that solution to EclipseLink, but I cannot seem to figure it out. Thanks


You can explicitly specify the names of the join tables by @JoinTable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜