Spring Data Rest @EmbeddedId cannot be constructed from Post Request

前端 未结 1 1623
北恋
北恋 2021-01-13 12:30

I have a JPA entity Person and an entity Team. Both are joined by an entity PersonToTeam. This joining entity holds a many-to-one relation to

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

    After running into the same issue I found a solution. Your code should be fine, except I return new PersonToTeamId() instead of the DefaultIdConverter if id is null in fromRequestId().

    Assuming you are using JSON in your post request you have to wrap personId and teamId in an id object:

    {
      "id": {
        "personId": "foo",
        "teamId": "bar"
      },
      ...
    }
    

    And in cases where a part of the @EmbeddedId is not a simple data type but a foreign key:

    {
      "id": {
        "stringId": "foo",
        "foreignKeyId": "http://localhost:8080/path/to/other/resource/1"
      },
      ...
    }
    
    0 讨论(0)
提交回复
热议问题