title: how to update inner objects of an entity in springboot
body: <p>Am relatively new to springboot and I have a scenario.I have users and I have jobs. A user can apply to many jobs and a job can be applied by multiple user.I have job and user entities with bidirectional relationship as follows</p>
  <pre><code>@ManyToMany(cascade = CascadeType.ALL)
      @JoinTable(name = &quot;job_applications&quot;)
      @JsonBackReference
      private Collection&lt;JobApplicant&gt; applicants= new ArrayList&lt;&gt;();
  
  @ManyToMany(mappedBy = &quot;applicants&quot;,fetch = FetchType.LAZY)
       @JsonManagedReference
      private Collection&lt;Job&gt; jobs= new ArrayList();
  </code></pre>
  <p>The challenge I want to associate a user with a job programatically and this is what I was trying in my service class</p>
  <pre><code>public void addJobToUserJobList(int useId,int jobId) {
          Job job=jobRepository.getOne(jobId);
          System.out.println(&quot;Job found: &quot;+job.getName());
          JobApplicant applicant= applicantRepo.getOne(useId);
          Set&lt;Job&gt;jobslist= new HashSet();
          jobslist.add(job);
          applicant.setJobs(jobslist);
          applicantRepo.save(applicant);
          jobRepository.save(job);
      }
  </code></pre>
  <p>When I hit <strong>applicants/1/25</strong> end-point this code in the controller the join table is not updated.</p>
  <pre><code>@RequestMapping(value = &quot;/applicants/{userid}/{jobId}&quot;, method = { RequestMethod.PUT, 
  RequestMethod.GET })
  public void applyToJob(@PathVariable int userid,@PathVariable int jobId) {
          jobService.addJobToUserJobList(userid, jobId);
  }
  </code></pre>
  <p>Is there a better approach to doing this ?</p>