Spring Data REST - Detected multiple association links with same relation type

前端 未结 1 1823
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 08:34

I am trying to doing a simple Spring app. It needs to expose REST endpoints and save it to a relational database.

I took your sample project, http://spring.io/guides

相关标签:
1条回答
  • 2021-01-04 09:11

    The reason for that is pretty simple: the relation names for associated entities are derived from the property names of the containing class. So both PersonDetails and PersonChildren want to create an outbound link to a Person named person. If we rendered that, it would look something like this

    { _links : { 
       person : { href : … }, <- the one from PersonDetails
       person : { href : … }  <- the one from PersonChildren
    }
    

    This is of course invalid. Also, lining up the two links in an array would not allow you to distinguish between the two links anymore (which one is coming from PersonDetails and which one is coming from PersonChildren.

    So there are a few options here:

    1. Manually name the relations of those types. You can annotate the Person properties with @RestResource and configure the rel attribute of the annotation to something different than person.
    2. You want any of the two not exported at all. The very same annotation can be used to prevent the link from being rendered at all. Simply set the exported flag in @RestResource to false and the link will not be rendered. This might be useful if the pointer e.g. from PersonDetails is just relevant within the code, but actually not in a JSON representation.
    0 讨论(0)
提交回复
热议问题