title: spring data rest mongodb java.lang.IllegalArgumentException: PersistentEntity must not be null
body: <p>I'm trying to access a mongodb collection via SDR. Working with following versions currently</p>
  
  <pre><code>    &lt;spring.version&gt;4.1.9.RELEASE&lt;/spring.version&gt;
      &lt;spring-data-rest&gt;2.4.4.RELEASE&lt;/spring-data-rest&gt;
      &lt;spring-data-mongodb&gt;1.8.4.RELEASE&lt;/spring-data-mongodb&gt;
  </code></pre>
  
  <p>My repository looks like</p>
  
  <pre><code>@RepositoryRestResource
  @PreAuthorize("hasAuthority('ROLE_USER')")
  public interface LinksRepository extends MongoRepository&lt;Link, String&gt; {
  Page&lt;Link&gt; findAllByUsefulURLRegex(@Param("regex") String regex, Pageable p);
  </code></pre>
  
  <p>My model is defined as follows</p>
  
  <pre><code>@Document(collection = "links")
  public class Link {
      public Link() {}
      @Id
      private String id;
  </code></pre>
  
  <p>When I hit <a href="http://localhost:9090/api/links" rel="noreferrer">http://localhost:9090/api/links</a> I get the following exception  </p>
  
  <pre><code>java.lang.IllegalArgumentException: PersistentEntity must not be null!
      at org.springframework.util.Assert.notNull(Assert.java:112)
      at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.&lt;init&gt;(PersistentEntityResource.java:139)
      at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.&lt;init&gt;(PersistentEntityResource.java:122)
      at org.springframework.data.rest.webmvc.PersistentEntityResource.build(PersistentEntityResource.java:114)
      at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.wrap(PersistentEntityResourceAssembler.java:102)
      at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:83)
      at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:45)
      at org.springframework.data.web.PagedResourcesAssembler.createResource(PagedResourcesAssembler.java:182)
      at org.springframework.data.web.PagedResourcesAssembler.toResource(PagedResourcesAssembler.java:115)
      at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.entitiesToResources(AbstractRepositoryRestController.java:127)
      at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResources(AbstractRepositoryRestController.java:88)
      at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResource(AbstractRepositoryRestController.java:110)
      at org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(RepositorySearchController.java:185)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:965)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:856)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
  </code></pre>
  
  <p>Digging a little bit I found MongoMappingContext does not have the class <strong>Link</strong> as it should (I guess)</p>
  
  <p><a href="https://i.stack.imgur.com/XHXr8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XHXr8.png" alt="enter image description here"></a></p>
  
  <p>I spent few hours trying to figure it out but no luck. I'm <strong>not using spring boot</strong> and it feels it could be a ObjectMapper problem but I don't know, my domain and setup is simple....any help is greatly appreciated. </p>
  
  <p>Thanks in advance.</p>