Uploaded image for project: 'Spring Data REST'
  1. Spring Data REST
  2. DATAREST-523

Unable to augment collection association using POST

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.2 (Evans SR2), 2.3 GA (Fowler)
    • Component/s: None
    • Labels:
      None

      Description

      It seems that POSTing an item to an associated collection does not work as documented.

      According to the Spring Data REST documentation, POST method is supported for collections, so

      curl -i -X POST -H 'Content-type: text/uri-list' -d 'http://localhost:8080/artifacts/1' http://localhost:8080/collectors/1/artifacts

      should add an artifact to the (yet empty) collection. Unfortunately, it does not:

          HTTP/1.1 405 Method Not Allowed
          Server: Apache-Coyote/1.1
          Allow: GET, DELETE, PATCH, PUT
          Content-Type: application/json;charset=UTF-8
          Transfer-Encoding: chunked
          Date: Fri, 17 Apr 2015 22:54:59 GMT
          
          {"timestamp":1429311299117,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/collectors/1/artifacts"}
      

      My entities:

          @Data
          @Entity
          public class Collector {
              @Id
              @GeneratedValue
              private Long id;
          
              private String name;
          
              @OneToMany(mappedBy = "owner")
              private List<Artifact> artifacts;
          }
          
          @Data
          @Entity
          @Accessors(chain = true, fluent = true)
          public class Artifact {
          
              @Id
              @GeneratedValue
              private Long id;
          
              private String title;
          
              @ManyToOne
              @JoinColumn(name = "collector_id")
              private Collector owner;
          }
      

      The complete code is on Github.

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            endrec Endre Czirbesz
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: