title: How to choose MappingContext in spring-data-jpa (2x) + spring-rest-webmvc?
body: <p>I've got a Module A that provides authentication through users, groups and related classes. This module uses <code>org.springframework.data:spring-data-jpa:1.6.0.RELEASE</code> to access this data from a database. Of note might be that Module A uses a custom BaseRepository configured by extending JpaRepositoryFactoryBean, but removing this does not resolve the issue below.</p>
  
  <p>A second Module B also has some classes and repositories to manage, unrelated to the Module A classes, again using <code>spring-data-jpa</code> for storage, but connected to a different database. This project exposes it's repositories via REST using <code>org.springframework.data:spring-data-rest-webmvc:2.1.0.RELEASE</code>. Module B uses the classes in module A for authenticating users, but does not manipulate those class instances nor does it store any references.</p>
  
  <p>The issue I'm having now is that my module B REST APIs work flawlessly when Module A is not present (or with an older version not yet using spring-data-jpa), but when it is I present it breaks on creating self referential links with the below stacktrace:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot create self link for class Document! No persistent entity found!
  at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.getSelfLinkFor(PersistentEntityResourceAssembler.java:81) ~[spring-data-rest-webmvc-2.1.0.M1.jar:na]
  at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:64) ~[spring-data-rest-webmvc-2.1.0.M1.jar:na]
  at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:32) ~[spring-data-rest-webmvc-2.1.0.M1.jar:na]
  at org.springframework.data.web.PagedResourcesAssembler.createResource(PagedResourcesAssembler.java:144) ~[spring-data-commons-1.8.0.M1.jar:na]
  at org.springframework.data.web.PagedResourcesAssembler.toResource(PagedResourcesAssembler.java:96) ~[spring-data-commons-1.8.0.M1.jar:na]
  at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.entitiesToResources(AbstractRepositoryRestController.java:220) ~[spring-data-rest-webmvc-2.1.0.M1.jar:na]
  at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.resultToResources(AbstractRepositoryRestController.java:207) ~[spring-data-rest-webmvc-2.1.0.M1.jar:na]
  at org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(RepositoryEntityController.java:135) ~[spring-data-rest-webmvc-2.1.0.M1.jar:na]
  </code></pre>
  
  <p>See also: <a href="https://github.com/spring-projects/spring-data-rest/blob/master/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssembler.java#L80" rel="nofollow">https://github.com/spring-projects/spring-data-rest/blob/master/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssembler.java#L80</a></p>
  
  <p>It looks to be talking to the wrong <code>MappingContext</code> in the <code>RepositoryFactoryBeanSupport</code>, even if my <code>org.springframework.data.repository.support.Repositories</code> contains all the repositoryBeanNames from both Module A and Module B.</p>
  
  <p>Does anyone know how I can enforce the use of a particular MappingContext, perhaps through my extension of <code>RepositoryRestMvcConfiguration</code>?</p>
  
  <p>** <strong>Edit</strong> **<br>
  Here's an GitHub repository illustrating the problem:<br>
  <a href="https://github.com/timtebeek/dual-data-jpa-rest-webmvc" rel="nofollow">https://github.com/timtebeek/dual-data-jpa-rest-webmvc</a></p>
  
  <p>It's since been reported as a bug on the data-rest project:<br>
  <a href="https://jira.spring.io/browse/DATAREST-312" rel="nofollow">https://jira.spring.io/browse/DATAREST-312</a></p>