title: JPA: Update mapping table alone
body: <p>I have a Project and Employee entities, which has ManyToMany relationship like below.</p>
  
  <pre><code>@Entity
  public class Project {
       @Id @GeneratedValue
       private int projectId;
  
       private String projectName;
  
       // has some additional columns
  
       @ManyToMany(mappedBy = "projects")
       private List&lt;Employee&gt; emp = new ArrayList&lt;Employee&gt; ();
       ....
       .....
  
   }
  
  
   @Entity
  public class Employee {
       @Id @GeneratedValue
       private int id;
       private String firstName;
       private String lastName;
  
       @ManyToMany(cascade=CascadeType.ALL)
       List&lt;Project&gt; projects = new ArrayList&lt;Project&gt; ();
  
       ....
       ....
  }
  </code></pre>
  
  <p>When I use above entities, JPA create a mpping table 'Employee_Project' like below.</p>
  
  <pre><code>create table Employee_Project (emp_id integer not null, projects_projectId integer not null)
  </code></pre>
  
  <p>My question is, whenever new employee is added, I want to update both employee table and Employee_Project mapping table only, assume I know project id that I would like to map this employee to. (without touching project table/entity, I mean why should I provide complete project object, while saving employee entity alone, how can I do this via jpa?)</p>