我需要通过连接多个表在一个实体类中构建以下查询。
SELECT t1.column_id_1
FROM table1 t1,
Table2 t2,
Table3 t3,
Table4 t4,
Table5 t5
WHERE t1.COLUMN_ID_1 = t2. COLUMN _ID_1
AND t2.COLUMN_ID_2 = t3. COLUMN_ID_2
AND t3.COLUMN_ID_3 = t4. COLUMN_ID_3
AND t4.COLUMN_ID_4 = t5. COLUMN_ID_4
请分享一些想法
答案 0 :(得分:0)
这取决于您的模型如何映射到数据库。例如,如果T1映射到A
类,T2映射到B
类,并且A
被声明为:
@Entity @Table(name = "t1")
public class A {
@ManyToOne @JoinColumn(name = "COLUMN_ID_1")
private B b;
}
@Entity @Table(name = "t2")
public class B {
@Id @Column(name = "COLUMN_ID_1)
private Integer id;
}
然后在JPQL中你只需编写
select b.id
from A a
join a.b as b
以及其他表格。