【问题标题】:How to have 2 collections of the same type in JPA? (EclipseLink)如何在 JPA 中拥有 2 个相同类型的集合? (日食链接)
【发布时间】:2011-03-11 02:23:29
【问题描述】:

想知道如何执行How to have 2 collections of the same type in JPA? 中指定的操作,但使用 EclipseLink 而不是 Hibernate。请参阅下面的帖子:

我在 JPA 中有 2 个实体:Entry 和 评论。条目包含两个 评论对象的集合。

@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>();

要存储这样的对象,JPA+Hibernate 创建“条目”表、“评论”表 和单个“Entry_Comment”:

创建表Entry_Comment(Entry_id 整数不为空, postMortemComments_id 整数不是 空,pmnr 整数不为空, descriptionComments_id 整数不是 null,dnr 整数不为 null,主要 键(Entry_id,dnr),唯一 (descriptionComments_id),唯一 (postMortemComments_id))

对象存储失败 descriptionComments_id 和 postMortemComments_id 不能是“不是 空”。

如何存储包含两个的对象 相同类型的集合使用 JPA+休眠?

我确信将该解决方案转换为 EclipseLink 非常简单,但我似乎无法弄清楚。谢谢

【问题讨论】:

    标签: jpa eclipselink


    【解决方案1】:

    您可以通过@JoinTable明确指定连接表的名称

    【讨论】:

      猜你喜欢
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多