gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:15 25 4
gpt4 key购买 nike

我有一组 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

是否有另一种方法可以让父实体填充基于父过滤器过滤的子实体?

最佳答案

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

关于java - 如何在多个表上映射具有多个连接列的集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38152903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com