Saturday, August 26, 2017

Hibernate INNER join doesn't work..SQL Query Works…Weird Behavior

Leave a Comment

Query Returns zero records in HQL (Query 1 = Query 2 + Query 3):

Two OR conditions..Instead of returning results, it returns zero records

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 Returns Records in 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 Returns Zero Records in 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')); 

When we combine the condition - Query 1 results zero records

I suspect it is a hibernate bug or a default behaviour or query needs to be corrected.

Basically the OR and And condition doesn't work properly during joining multiple tables.

Thanks.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment