Retrieve the employees based on the below criteria where in
Departments and Employees entities are associated by One to Many
"DepartmentId value is NULL or passed in departmentId as
JPA by default does a inner join in between entities .The '.'
notation to mean an inner join unless it is explicietly stated to use
an outer join
select o from Employee o where o.departments.departmentId
is null or o.departments.departmentId=:departmentId
But the above jpql translates to below Sql
select * from Employees
t0,Departmemts t1 where (to.depratmentID is null) or (to.departmentId =
:1 )) and (to.departmentId = t1.departmentId))
To achieve the above query criteria use left outer join as given
o.departments as Dept where Dept is null or Dept.departmentId=:deptNo".
The above Left outer JPQL will rsult in below SQL.
Select * from Employees t0 where (((t0.departmentId IS
NULL) OR (t0.departmentId = :1))