title: Adding a resource to a collection using spring-data-rest
body: <p>My situation:
  I have an Organization that can have many workers. I am trying to add a new worker to an organization following <a href="https://stackoverflow.com/questions/25311978/posting-a-onetomany-sub-resource-association-in-spring-data-rest">this example</a> by the major contributing author of the SDR project and I get various errors (including 204 but nothing happens).</p>
  
  <p>Here are my entities and rest calls:</p>
  
  <pre><code>@Entity
  public class Organization {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
  
      @OneToMany
      @JoinTable(name = "OrganizationWorker", joinColumns = {@JoinColumn(name = "OrganizationID")},
              inverseJoinColumns = {@JoinColumn(name = "WorkerID")})
      private Set&lt;Worker&gt; workers = new LinkedHashSet&lt;&gt;();
  }
  
  public class Worker {
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private Long id;
  
      @NotNull
      private String givenName;
  
      @NotNull
      private String familyName;
  
      @NotNull
      private LocalDate dob;
  
      @NotNull
      private String nationalId;
  
      private byte[] photo;
  }
  </code></pre>
  
  <p>GET <a href="http://localhost:8080/hal" rel="nofollow noreferrer">http://localhost:8080/hal</a></p>
  
  <pre><code>{
      "_links": {
  
          "workers": {
              "href": "http://localhost:8080/hal/workers{?page,size,sort}",
              "templated": true
          }
      }
  }
  </code></pre>
  
  <p>POST <a href="http://localhost:8080/hal/workers" rel="nofollow noreferrer">http://localhost:8080/hal/workers</a></p>
  
  <pre><code>{
   "givenName": "James",
      "familyName": "Bond",
      "dob": "1970-01-01",
      "nationalId": "XXX-60-XXXX",
      "photo": null,
  }
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>Location: http://localhost:8080/hal/workers/8
  Date: Mon, 02 May 2016 16:53:02 GMT
  Server: Apache-Coyote/1.1
  Transfer-Encoding: chunked
  X-Application-Context: application
  Content-Type: application/hal+json;charset=UTF-8
  
  
  {
      "givenName": "James",
      "familyName": "Bond",
      "dob": "1970-01-01",
      "nationalId": "XXX-60-XXXX",
      "photo": null,
      "_links": {
          "self": {
              "href": "http://localhost:8080/hal/workers/8"
          },
          "worker": {
              "href": "http://localhost:8080/hal/workers/8"
          }
      }
  }
  </code></pre>
  
  <p>Final step, as per link in description:</p>
  
  <pre><code>curl -X PUT -H "ContentType: text/uri-list" http://localhost:8080/hal/organizations/2 -d 'http://localhost:8080/hal/workers/8'
  
  {
      "cause": null,
      "message": "Target bean is not of type of the persistent entity!"
  }
  </code></pre>
  
  <p>Doing some debug it's pretty obvious what the specific complaint is. The stack trace leads here:</p>
  
  <pre><code>@Override
  public PersistentPropertyAccessor getPropertyAccessor(Object bean) {
  
      Assert.notNull(bean, "Target bean must not be null!");
      Assert.isTrue(getType().isInstance(bean), "Target bean is not of type of the persistent entity!");
  
      return new BeanWrapper&lt;Object&gt;(bean);
  }
  </code></pre>
  
  <blockquote>
    <p>getType() -> Organization</p>
    
    <p>isInstance(bean) -> bean instance of org.springframework.hateoas.Resource</p>
  </blockquote>
  
  <p>Any input on this? I followed the instructions to the letter. </p>