title: Spring how to resolve entity uri in @RepositoryRestController
body: <p>I'm using Spring boot 1.5.3, Spring Data REST, Spring HATEOAS. Spring Data REST is amazing and does a perfect job, but sometimes it's needed custom business logic and therfore I need to create a custom controller.</p>
  
  <p>I'm going to use a @RepositoryRestController to benefit of Spring Data REST functionality (<a href="http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers" rel="nofollow noreferrer">http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers</a>).</p>
  
  <p>Because Spring Data REST use HATEOAS by default, I'm using that. I need a controller like this:</p>
  
  <pre><code>@RepositoryRestController
  @RequestMapping(path = "/api/v1/workSessions")
  public class WorkSessionController {
  
      @Autowired
      private EntityLinks entityLinks;
  
      @Autowired
      private WorkSessionRepository workSessionRepository;
  
      @Autowired
      private UserRepository userRepository;
  
      @PreAuthorize("isAuthenticated()")
      @RequestMapping(method = RequestMethod.POST, path = "/start")
      public ResponseEntity&lt;?&gt; start(@RequestBody(required = true) CheckPoint checkPoint) {
          Authentication auth = SecurityContextHolder.getContext().getAuthentication();
  
          if (checkPoint == null) {
              throw new RuntimeException("Checkpoint cannot be empty");
          }
  
          if (workSessionRepository.findByAgentUsernameAndEndDateIsNull(auth.getName()).size() &gt; 0) {
              // TODO return exception
              throw new RuntimeException("Exist a open work session for the user {0}");
          }
  
          // ...otherwise it's opened a new work session
          WorkSession workSession = new WorkSession();
          workSession.setAgent(userRepository.findByUsername(auth.getName()));
          workSession.setCheckPoint(checkPoint);
          workSession = workSessionRepository.save(workSession);
  
          Resource&lt;WorkSession&gt; resource = new Resource&lt;&gt;(workSession); 
          resource.add(entityLinks.linkFor(WorkSession.class).slash(workSession.getId()).withSelfRel());
          return ResponseEntity.ok(resource);
      }
  }
  </code></pre>
  
  <p>Because the parameter CheckPoint must be an existant resource, I want the client send the link of the resourse (like you can do in Spring Data REST POST methods).
  Unfortunately when I try to do that, server side I receive an empty CheckPoint object.</p>
  
  <p>I already read <a href="https://stackoverflow.com/questions/37186417/resolving-entity-uri-in-custom-controller-spring-hateoas">Resolving entity URI in custom controller (Spring HATEOAS)</a> and <a href="https://stackoverflow.com/questions/43601604/converting-uri-to-entity-with-custom-controller-in-spring-data-rest/43617946">converting URI to entity with custom controller in spring data rest?</a> and expecially <a href="https://stackoverflow.com/questions/32513123/accepting-a-spring-data-rest-uri-in-custom-controller">Accepting a Spring Data REST URI in custom controller</a>.</p>
  
  <p>I'm wondering if there is a best practice to do this avoiding to expose id to the client, followind so the HATEOAS principles.</p>