jpa - 如何在JPA中拥有2个相同类型的集合? (Eclipse 链接)

标签 jpa eclipselink

想知道如何执行 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/

相关文章:

java - 如何按子句顺序指定运算符?

java - 使用 eclipselink.media-type 值 : application/json 设置 Marshaller 属性时出现 PropertyException

java - 如果我们没有在 OneToMany 注释中指定mappedBy 属性怎么办?

java - JBoss Eclipselink 不在 postgresql 中的 create-tables/create-or-extend-tables 上创建索引

java - 如何在 eclipselink 中禁用缓存

jpa-2.0 - 标准 API : can I access a given alias by its name

java - JAXB 2.x 和 Ant

java - 具有不同类的单个类中多个 @oneToMany 关联的持久性问题

java - 我们可以使用 hibernate 连接到 LDAP

java - 在 JPA、Hibernate 中验证用户名长度的最佳方法