0

We're using spring-data-rest 2.6.8 with spring-boot 1.5.8 and it's awesome! We found some strange behavior, nonetheless.

When we do a GET to /rest/students/search/findByTeacher?teacher=/rest/teachers/1 everything runs smoothly. SDR converts the teacher URI into a teacher Entity and we get a list of students.

When we provide a different URI (that resolves to the same object), the system can't do the conversion: /rest/students/search/findByTeacher?teacher=/rest/class/2/teacher

Currently we are doing this in two steps. First we GET the /rest/class/2/teacher and then we use the _links.self.href (/rest/teachers/1) to do our search.

Is there a way to configure SDR to avoid this 2-step process?

1 Answers1

1

I do not think it is possible. Spring Data Rest when resolving the links works in a way that basically it grabs the url, removes baseUri from the beginning, then it tries to match next part of the URL to the repository {teachers} and then queries the repository using findOne method. In this case the url /rest/teachers/1 is simply identifier of the resource (without hateoas it would be sth like teacherID=1)

The problem with querying /rest/class/2/teacher is that you do not know to what it will be resolved - it might be single element, it might be a list, it might be a null etc. because this is not an identifier to the resource, but a link to another one.

Paweł
  • 148
  • 1
  • 8
  • Ok. Maybe it is not possible. But it could be a nice enhancement, since SDR could derive easily what object the link is referring. I'm actually doing one more GET request just to get the cannonical ._links.self.href. I'll file an enhancement request Thanks anyway. – Daniel Silveira Dec 03 '17 at 14:02