Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate JPA标准(和JPQL)右外部联接_Hibernate_Jpa - Fatal编程技术网

Hibernate JPA标准(和JPQL)右外部联接

Hibernate JPA标准(和JPQL)右外部联接,hibernate,jpa,Hibernate,Jpa,我有两个实体A,B,关系正在进行中,可选,从A到B的一对多(多面),我想选择每个B及其相关的A(或者如果没有与该B相关的A,我希望为空),使用右外部联接可以很容易地做到这一点,但是hibernate在criteria API中不支持右外部联接,因此我需要解决这个问题。根据您的场景,您希望使用左联接。像 select b from B b left join A a where a.fkey is null 或者,如果在加入之前需要任何条件,请使用 select b from B b left

我有两个实体A,B,关系正在进行中,可选,从A到B的一对多(多面),我想选择每个B及其相关的A(或者如果没有与该B相关的A,我希望为空),使用右外部联接可以很容易地做到这一点,但是hibernate在criteria API中不支持右外部联接,因此我需要解决这个问题。

根据您的场景,您希望使用左联接。像

select b from B b left join A a 
where a.fkey is null
或者,如果在加入之前需要任何条件,请使用

select b from B b left join A a with a.type = 1
where a.fkey is null
这将服务于与“和”和“开”条款类似的目的

例如:

select t from Template t left join t.profiles p with p.type = 1
where p.id is null

这将获得所有没有类型为1的配置文件的模板。如果关联未按您导航的方向建模,则无法使用
标准
API执行联接。您可以尝试使用HQL并编写一个与您想要的右外部联接等效的ANSI-89联接(希望RDBM的优化器能够有效地执行联接)。我决定不为此使用Criteria API,只使用JPQL“从右联接a中选择b,a a.lotsofB”