Multiple Repositories for the Same Entity in Spring Data Rest

Gregor picture Gregor · Mar 20, 2016 · Viewed 8.7k times · Source

Is it possible to publish two different repositories for the same JPA entity with Spring Data Rest? I gave the two repositories different paths and rel-names, but only one of the two is available as REST endpoint. The point why I'm having two repositories is, that one of them is an excerpt, showing only the basic fields of an entity.

Answer

domgom picture domgom · Jun 1, 2016

The terrible part is not only that you can only have 1 spring data rest repository (@RepositoryRestResource) per Entity but also that if you have a regular JPA @Repository (like CrudRepository or PagingAndSorting) it will also interact with the spring data rest one (as the key in the map is the Entity itself). Lost quite a few hours debugging random load of one or the other. I guess that if this is a hard limitation of spring data rest at least an Exception could be thrown if the key of the map is already there when trying to override the value.