spring-projects / spring-projects/spring-data-rest

Polymorphic repositories do not properly represent subclasses as CollectionModel

Open
#2,094 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jan 17, 2022.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

I've been trying to represent a hierarchy of objects under a single entry point but Spring Data Rest does not represent a collection resource of instances under the same common collectionRel specified in the polymorphic repository.
This demo project illustrates the problem.
In the project I define an abstract entity "Club" and a sutype entity "SailingClub". I then define the single polymorphic repository

@RepositoryRestResource(path = "clubs", collectionResourceRel = "clubs", itemResourceRel = "clubs")
public interface ClubRepository extends JpaRepository<Club, Long> {
}

With only this configuration, all the instances of SailingClub will go under "_embedded.sailingClubs" whereas I'd expected they would go under "_embedded.clubs" , considering there is not repository defined for SailingClub.
To try and correct this I tried annotating the domain class as

@Entity
@RestResource(path = "clubs")
@Relation(itemRelation = "clubs", collectionRelation = "clubs")
@DiscriminatorValue("Sailing")
public class SailingClub extends Club {
...
}

but without any effect because the EVO inflector is present by default because imported transitively by spring-data-rest-core so the AnnotationLinkRelationProvider is not used in TypeBasedCollectionResourceMapping, which I think is not desirable and the AnnotationLinkRelationProvider should take precedence over the one based on the EVO inflector, at least in my opinion.

Am I missing anything here? I could not find anything specific in the documentation or on Internet. I've also debugged the framework code and, for what I could understand, what I'm trying to do, does not seem supported.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.