Skip to content

Commit c682ebb

Browse files
committed
RepositoryResourceMappings now processes all entities to detect repository mappings.
We now consider all registered PersistentEntity instances and try to detect repository metadata for them. A case we didn't cover before was that a repository was declared for an aggregate super type but the actual child aggregate class didn't have a dedicated repository declared. While this is a perfectly valid scenario, the mapping information was broken as it fell back on the plain domain type information and produced paths and relation names derived from that, even if there's a super type repository available. Thus, solely traversing the aggregate types we have repositories registered for is not enough. We now traverse all known PersistentEntity types and also register repository metadata for all types that are assignable to a known domain type. The latter is actually implemented in Spring Data Commons' Repositories via spring-projects/spring-data-commons#2406.
1 parent 29f0fd1 commit c682ebb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/RepositoryResourceMappings.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,21 @@ public RepositoryResourceMappings(Repositories repositories, PersistentEntities
6161

6262
this.repositories = repositories;
6363
this.configuration = configuration;
64-
this.populateCache(repositories, configuration);
64+
this.populateCache(entities, configuration);
6565
}
6666

67-
private void populateCache(Repositories repositories, RepositoryRestConfiguration configuration) {
67+
private void populateCache(PersistentEntities entities, RepositoryRestConfiguration configuration) {
6868

69-
for (Class<?> type : repositories) {
69+
for (PersistentEntity<?, ? extends PersistentProperty<?>> entity : entities) {
70+
71+
Class<?> type = entity.getType();
72+
73+
if (!repositories.hasRepositoryFor(type)) {
74+
continue;
75+
}
7076

7177
RepositoryInformation repositoryInformation = repositories.getRequiredRepositoryInformation(type);
7278
Class<?> repositoryInterface = repositoryInformation.getRepositoryInterface();
73-
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(type);
7479

7580
RepositoryDetectionStrategy strategy = configuration.getRepositoryDetectionStrategy();
7681
LinkRelationProvider provider = configuration.getRelProvider();

0 commit comments

Comments
 (0)