Hibernate INNER join没有工作...... SQL查询工作......奇怪的行为

时间:2017-08-02 04:30:16

标签: hibernate

查询在HQL中返回零记录(查询1 =查询2 +查询3):

两个OR条件。它不返回结果,而是返回零记录

from Employee as emp where empState = 'ACTIVE' and exists (from EmployeeOrg as 
EmployeeOrg where 52 = 52 and ((EmployeeOrg.empDetailTable is null and 
EmployeeOrg.empId like '10002') or (EmployeeOrg.empDetailTable is not null and 
EmployeeOrg.empDetailTable.empId like '10002')));

Query2以HQL方式返回记录:

from Employee as emp where empState = 'ACTIVE' and exists (from EmployeeOrg 
as EmployeeOrg where 52 = 52 and ((EmployeeOrg.empDetailTable is null and 
EmployeeOrg.empId like '10002')));

Query3在HQL中返回零记录

from Employee as emp where empState = 'ACTIVE' and exists (from EmployeeOrg 
as EmployeeOrg where 52 = 52 and (EmployeeOrg.empDetailTable is not null and 
EmployeeOrg.empDetailTable.empId like '10002'));

当我们结合条件时 - 查询1结果为零记录

我怀疑这是一个hibernate错误,或者需要更正默认行为或查询。

基本上,OR和And条件在连接多个表时不能正常工作。

感谢。

0 个答案:

没有答案