Search code examples
jpaeclipselinkjpa-2.1

Select all users in a group beside currentUser


I'd like to select all the users beside the current user in a given group. The relationship between group and user is many-to-many.

At the moment my query selects all users in a given group.

SELECT g.users FROM Group g WHERE g.groupName =:groupName

I didn't manage to get what I wanted, I don't know where to add a condition (in the where clause the condition is not met so I have an empty list of users).


Solution

  • You need a JOIN between the 2 entities:

    SELECT u FROM User u JOIN Group g WHERE g.groupName =: groupName