title: Spring data REST findBy nested entity
body: <p>I have a Spring Boot project using Spring-data-rest for generating my REST interface and I am trying to allow pagination for nested resources. I followed this <a href="https://stackoverflow.com/questions/27539550/use-case-for-pagination-of-embedded-resources">workaround</a> and got stuck with implementing the findBy query.</p>
  
  <p>I have the following Device entity:</p>
  
  <pre><code>@Entity
  @Table(name = "devices")
  public class Device extends ResourceSupport {
  
    ...
  
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;
  }
  </code></pre>
  
  <p>I need to query it using userId:</p>
  
  <pre><code>@RequestMapping(path = "/users/{id}/devices", method = RequestMethod.GET)
  public ModelAndView getUserDevices(@PathVariable Integer id) {
      return new ModelAndView("forward:/devices/search/findByUserId?userId=" + id);
  }
  </code></pre>
  
  <p>So I created the following method in my DeviceRepository:</p>
  
  <pre><code>@Repository
  public interface DeviceRepository extends JpaRepository&lt;Device, Long&gt; {
  
    @PreAuthorize("hasRole('ROLE_ADMIN') OR @securityCheck.check(#user, authentication)")
    Page&lt;Device&gt; findByUserId(@Param("user") User user, Pageable pageable);
  
  }
  </code></pre>
  
  <p>But I am getting the following exception when trying to send request to this endpoint: </p>
  
  <pre><code>Unable to locate Attribute  with the the given name [id] on this ManagedType [com.example.User]
  </code></pre>
  
  <p>Does anyone have some suggestion what I am doing wrong?</p>
  
  <p>EDIT:
  Thank you for your responses, I changed the method to </p>
  
  <pre><code>Page&lt;Device&gt; findByUser_UserId(@Param("user") User user, Pageable pageable);
  </code></pre>
  
  <p>My user entity contains a <code>userId</code> field.</p>
  
  <p>However, now I am getting the following exception:</p>
  
  <pre><code>{
      "cause": {
          "cause": {
              "cause": null,
              "message": "Cannot resolve URI 1. Is it local or remote? Only local URIs are resolvable."
          },
          "message": "Failed to convert from type [java.net.URI] to type [@org.springframework.data.repository.query.Param com.example.User] for value '1'; nested exception is java.lang.IllegalArgumentException: Cannot resolve URI 1. Is it local or remote? Only local URIs are resolvable."
      },
      "message": "Failed to convert 1 into me.originalsin.user.model.User!"
  }
  </code></pre>
  
  <p>So it seems I am using the query wrongly?</p>