0

Suppose you have an Entity User that has a ManyToOne relationship with Group.

How do you search for all users that belong to a certain group?

You can't just create an endpoint with a query parameter like /users?group=1 because in SDR you are forced to ignore IDs and all entities are referenced by their full URL http://host/groups/1

So how do you search by specifying your search parameter?

erotsppa
  • 14,248
  • 33
  • 123
  • 181

1 Answers1

1

This should work:

@Query("Select u from User u where u.group = :group");
public List<User> findByGroup(Group group);

Called with:

/users/search?group=http://host/groups/1

Alan Hay
  • 22,665
  • 4
  • 56
  • 110
  • I’m going to test it later but even if it works is this a good idea? I’ve never seen a URL as a parameter in a URL – erotsppa Dec 20 '19 at 16:53
  • You can always expose the id and work with that if you find it better. https://stackoverflow.com/questions/30912826/expose-all-ids-when-using-spring-data-rest – Alan Hay Dec 21 '19 at 00:21