【发布时间】:2012-10-25 05:18:03
【问题描述】:
什么是 jpql 等价于以下 SQL 查询:
select * from App left outer join App_Child on (App.id=App_Child.id and App_Child.status = 'active') where App.status='active' and App.id=1;
样本数据:
ij> select * from App;
ID |STATUS
----------------------
1 |active
2 |active1
3 |active3
5 |active
4 rows selected
ij> select * from App_Child;
ID |STATUS |D
----------------------------------
1 |active |1
2 |active11 |2
1 |active111 |3
1 |active |4
4 rows selected
ij> select * from App left outer join App_Child on (App.id=App_Child.id and App_Child.status = 'active') where App.status='active' and App.id=1;
ID |STATUS |ID |STATUS |D
---------------------------------------------------------
1 |active |1 |active |1
1 |active |1 |active |4
2 rows selected
ij> select * from App left outer join App_Child on (App.id=App_Child.id and App_Child.status = 'active') where App.status='active' and App.id=5;
ID |STATUS |ID |STATUS |D
---------------------------------------------------------
5 |active |NULL |NULL |NULL
1 row selected
编辑:我们正在使用 jpa 2.0
【问题讨论】:
-
你能用子查询代替连接吗? JPQL 允许子查询,我过去曾将其用作解决方法。
-
你能发布你的子查询解决方法吗?
-
我发布了解决方法。我很想知道它是否有帮助?
标签: java sql database hibernate jpql