I don´t get that simple query working and i don´t now why. i have three entities (just semantics code):
Profile {
@OneToMany
Set<ProfileClubMapping> clubs
String username
...
}
ProfileClubMapping {
@ManyToOne
Profile profile
@ManyToOne
Club club
...
}
Club {
@OneToMany
Set<ProfileClubMapping> profiles
...
}
now i want to select every profile which contains a string in the username and the ProfileClubMapping with a certain Club id. If no ProfileClubMapping exists just return null for the ProfileClubMapping. I tried something like that:
SELECT p,pcm FROM Profile p LEFT JOIN p.clubs pcm ON pcm.club.id = :clubId WHERE UPPER(p.username) = UPPER(:str)
but this query only returns me the profiles which have an ProfileClubMapping. Anyone an idea?
EDIT: maybe the sql query helps:
SELECT p.USERNAME, pcm.CLUB_ID FROM PROFILE AS p LEFT JOIN PROFILECLUBMAPPING AS pcm ON pcm.PROFILE_ID = p.ID AND pcm.CLUB_ID = :clubId WHERE p.USERNAME LIKE '%:username%';