我希望你能帮助我。
表 A 与表 B 有一个多列连接,其中一个 JoinColumns 可以为空...
@Entity
@Table(name = "TABLE_A")
public class TableA {
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumns({
@JoinColumn(name = "KEY1_TABLE_A", referencedColumnName = "KEY1_TABLE_B"),
@JoinColumn(name = "KEY2_TABLE_A", referencedColumnName = "KEY2_TABLE_B"),
@JoinColumn(name = "GROUP_TABLE_A", referencedColumnName = "GROUP_TABLE_B", nullable = true)})
private TableB typeB;
}
在 TableB 对象中的列
- TABLE_B#KEY1_TABLE_B(非空)
- TABLE_B#KEY2_TABLE_B(非空)
- TABLE_B#GROUP_TABLE_B(可为空)
被映射为字符串。touple KEY1_TABLE_B /KEY2_TABLE_B /GROUP_TABLE_B 是唯一键。
生成的SQL如下(略)
SELECT
*
FROM
table_a this_
INNER JOIN table_b b_ ON
this_.KEY1_TABLE_A = b_.KEY1_TABLE_B AND
this_.KEY2_TABLE_A = b_.KEY2_TABLE_B AND
this_.GROUP_TABLE_A = b_.GROUP_TABLE_B <-- here is the issue: works only with "is not null" on Oracle
WHERE
this.XYZ=<some-conditions-here>;
如果我直接写 SQL 它应该是这样的
on ... AND (
(this_.GROUP_TABLE_A = b_.GROUP_TABLE_B)
OR (this_.GROUP_TABLE_A is null and b_.GROUP_TABLE_B is null)
)
感谢您的想法和想法!