如何在多个表上映射具有多个连接列的集合?

时间:2016-07-01 19:40:56

标签: java hibernate

我有一组4个表设置如下:

Table parent_a
id | other_columns...

Table parent_b
id | filter | other_columns...

Table child_a
id | parent_id | other_columns...

Table child_b
id | filter | other_columns...

实体设置如下:

@Entity
@Table(name = "parent_a")
@SecondaryTable(name = "parent_b")
public class Parent {
  @Id
  @GeneratedValue
  @Column(name = "id")
  private Integer id;

  @Column(name = "filter", table = "parent_b")
  private String filter;

  @OneToMany
  @JoinColumns({
    @JoinColumn(name = "parent_id"),
    @JoinColumn(name = "filter", table = "child_b")
  })
  private List<Child> children;
  // Mappings for other columns, getters/setters
}

@Entity
@Table(name = "child_a")
@SecondaryTable(name = "child_b")
public class Child {
  @Id
  @GeneratedValue
  @Column(name = "id")
  private Integer id;

  @Column(name = "filter", table = "child_b")
  private String filter;
  // Mappings for other columns, getters/setters
}

当我部署我的应用程序时,我得到以下异常:

org.hibernate.cfg.NotYetImplementedException: Collections having FK in secondary table

是否有其他方法可以使用基于父过滤器过滤的子实体填充父实体?

1 个答案:

答案 0 :(得分:0)

我使用实体监听器在父实体的加载时填充集合。