I have a ClassRoom class with a name field, and a Student class with a ClassRoom field. Not all students have a classroom.
I want a list of all students with their classroom name (or an empty string if no classroom). Using this JPQL query :
Select s.name, s.classRoom.name from Student s LEFT JOIN s.classRoom
The problem is that this returns only students with a classroom. The right generated SQL should be
Select s.name, c.name from student s left join classroom c on c.id=s.classroomid
Which returns all students, but the s.classRoom.name construct seems to force an inner join in the generated SQL.
Using a chained expression like
s.classRoom.namegenerates an inner join. You need to assign an alias to the left joined entity and use that alias: