I'm using Spring Boot, Spring HATEOAS, Spring Data REST, Hibernate.
All my beans have a Repository in order to expose methods via REST. I would like to use a @PathVariable in the Repository without create a specific controller.
This is what I would like to do:
@PreAuthorize("isAuthenticated()")
publicinterfaceTicketBundleRepositoryextendsJpaRepository<TicketBundle, Long> {
@Transactional(readOnly = true)
@RestResource(rel = "ticketBundleNotes", path = "/ticketBundles/{id}/notes")
@RequestMapping(method = RequestMethod.GET, path = "/ticketBundles/{id}/notes")
@Query("SELECT n FROM TicketBundle tb JOIN tb.notes n WHERE tb.id=:id ORDER BY n.createdDate DESC, n.id DESC")
publicPage<Note> getNotes(@PathVariable("id") longid, Pageablepageable);
Unfortunately this doesn't work and when I try to call the endpoint I've a http 405 error. I guess the @PathVariable is not supported.
So I turned down to this solution that I don't like so much though:
@Transactional(readOnly = true)
@Query("SELECT n FROM TicketBundle tb JOIN tb.notes n WHERE tb.id=:id ORDER BY n.createdDate DESC, n.id DESC")
publicPage<Note> getNotes(@Param("id") longid, Pageablepageable);
In short, instead to have a path variable I ask for an url parameter. This works fine but I'm not able to reach my goal to have an enpoint uri like htttp://localhost/api/ticketBundles/{id}/notes.
We currently have no plans to add support for this. Writing a controller to front that method invocation is trivial and supporting @RequestMapping on repository query methods creates more questions than it answers
Thanks for your reply Oliver. Writing a controller is not a big deal but was absolutely fastester use the repository due to facilities (@Query and Pagination). Anyway I understand your point.
Daniele Renda opened DATAREST-1154 and commented
I'm using Spring Boot, Spring HATEOAS, Spring Data REST, Hibernate.
All my beans have a Repository in order to expose methods via REST. I would like to use a
@PathVariable
in the Repository without create a specific controller.This is what I would like to do:
Unfortunately this doesn't work and when I try to call the endpoint I've a http 405 error. I guess the
@PathVariable
is not supported.So I turned down to this solution that I don't like so much though:
In short, instead to have a path variable I ask for an url parameter. This works fine but I'm not able to reach my goal to have an enpoint uri like htttp://localhost/api/ticketBundles/{id}/notes.
There is a question opened here: https://stackoverflow.com/questions/46892724/use-pathvariable-into-a-repository-managed-by-spring-data-rest.
I am asking if this could be a new function to add to SDR
Affects: 3.0 GA (Kay)
The text was updated successfully, but these errors were encountered: