spring-data-rest icon indicating copy to clipboard operation
spring-data-rest copied to clipboard

Polymorphic repositories do not properly represent subclasses as CollectionModel

Open alienisty opened this issue 3 years ago • 0 comments

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.

alienisty avatar Jan 05 '22 10:01 alienisty