I have a group with a one to many relationship with users. (A group can have zero or 1+ users)
I was to write a jpa query that returns a groups if it has not users attached or if it does have users the id matches my id.
For example if I have group 1 contain user 1 and user 2. group 2 containing no users.
If I was user 3 I want to return group 2 only.
If I was user 2 then I want to return group 1 and group 2
Can I do this in JPA? I know about the IS EMPTY part of JPQL so I can get group 2 returned regardless of user. My problem is how to query inside the list.
Any pointers would be good.
Thank for any help
I think I have it. The answer is to left join with the list.
For example
Groups is my entity which contains a list of users