title: Spring boot JPA save manytomany relationship
body: <p>I am trying to store a manytomany relationship but it not stores the relationship.</p>
  <p>The following code has generated 3 tables.</p>
  <p>Soldier, medal and soldier_medals.</p>
  <p>The service just make a call to a CRUD Interface with save(soldier).</p>
  <p>It stores correctly the soldier, but it not fill any row at the soldier_medals table.</p>
  <p>This is the JSON I send to the server:</p>
  <pre><code>{
          &quot;abbreviatedSequence&quot;: &quot;XDF&quot;,
          &quot;medals&quot;: [
              {
                  &quot;name&quot;: &quot;Purple&quot;,
                  &quot;id&quot;: 1
              },
              {
                  &quot;name&quot;: &quot;Red&quot;,
                  &quot;id&quot;: 2
              }
          ],
          &quot;sequence&quot;: &quot;XDFREE&quot;,
          &quot;name&quot;: &quot;Savier&quot;
      }
  </code></pre>
  <p><strong>Employee.java</strong></p>
  <pre><code>@Entity(name=&quot;employees&quot;)
  @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  public class Employee {
      @Id
      @GeneratedValue(generator=&quot;increment&quot;)
      @GenericGenerator(name=&quot;increment&quot;, strategy = &quot;increment&quot;)
      private Long id;
      
      private String name;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  <p><strong>Soldier.java</strong></p>
  <pre><code>@Entity(name=&quot;soldier&quot;)
  public class Soldier extends Employee{
      
      private String sequence;
      
      private String abbreviatedSequence;
      
      @ManyToMany(fetch = FetchType.LAZY, mappedBy = &quot;soldiers&quot;)
      private List&lt;Medal&gt; medals;
      
      public List&lt;Medal&gt; getMedals() {
          return medals;
      }
      
      public void setMedals(List&lt;Medal&gt; medals) {
          this.medals = medals;
      }
      
      public String getSequence() {
          return sequence;
      }
  
      public void setSequence(String sequence) {
          this.sequence = sequence;
      }
  
      public String getAbbreviatedSequence() {
          return abbreviatedSequence;
      }
  
      public void setAbbreviatedSequence(String abbreviatedSequence) {
          this.abbreviatedSequence = abbreviatedSequence;
      }
      
  }
  </code></pre>
  <p><strong>Medal.java</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;medal&quot;)
  public class Medal {
      @Id
      @Column(name = &quot;ID&quot;)
      @GeneratedValue(strategy = GenerationType.AUTO, generator = &quot;medal_seq&quot;)
      @SequenceGenerator(name = &quot;medal_seq&quot;, sequenceName = &quot;medal_seq&quot;, allocationSize = 1)
      private Long id;
  
      @Column(name = &quot;NAME&quot;, length = 50, unique = true)
      @NotNull
      @Size(min = 3, max = 50)
      private String name;
      
      @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
      @JoinTable(name = &quot;soldier_medals&quot;, joinColumns = {
              @JoinColumn(name = &quot;medal_id&quot;, nullable = false, updatable = false) },
              inverseJoinColumns = { @JoinColumn(name = &quot;soldier_id&quot;,
                      nullable = false, updatable = false) })
      private List&lt;Soldier&gt; soldiers;
  
      
      public List&lt;Soldier&gt; getSoldiers() {
          return soldiers;
      }
      
      public void setSoldiers(List&lt;Soldier&gt; soldiers) {
          this.soldiers = soldiers;
      }
      
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  <p><strong>SoldierController.java</strong></p>
  <pre><code>@RestController
  public class SoldierController {
      @Autowired
      private SoldierService soldierService;
      
      @RequestMapping(value=&quot;/api/contextsource/soldier&quot;,method= RequestMethod.POST)
      public Soldier addSoldier(@RequestBody Soldier soldier) {       
          return soldierService.addSoldier(soldier);
      }
      
  }
  </code></pre>