想知道如何执行 How to have 2 collections of the same type in JPA? 中指定的操作,但使用 EclipseLink 而不是 Hibernate。请参阅下面的帖子:
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, 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?
我确信将该解决方案转换为 EclipseLink 非常简单,但我似乎无法弄清楚。谢谢
最佳答案
您可以通过@JoinTable
显式指定连接表的名称
关于jpa - 如何在JPA中拥有2个相同类型的集合? (Eclipse 链接),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5268315/