title: Spring Boot: Can not POST into ManyToMany Relation
body: <p>I have two Entities <code>Meal</code> and <code>Mealplan</code> that are in a @ManyToMany Relation. Each Mealplan can have different Meals and each Meal can be in multiple Mealplans.</p>
  
  <pre><code>@Entity
  public class Meal {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
      private String name;
      private BigDecimal price;
      private String type;
  
  @ManyToMany(mappedBy = "mealsPerWeek")
  private List&lt;Mealplan&gt; mealplan;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Entity
  public class Mealplan {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
      private int week;
  
      @ManyToMany
      private List&lt;Meal&gt; mealsPerWeek;
  </code></pre>
  
  <p>Since I have added the ManyToMany Relation, I can't add a Meal by @Postmapping it into the API.</p>
  
  <p><strong>MealController</strong></p>
  
  <pre><code>@RestController
  @RequestMapping("/meal")
  @CrossOrigin(origins = "*", allowedHeaders = "*")
  public class MealController {
  
      @PostMapping
      public void addMeal(@RequestBody Meal meal) {
          mealRepository.save(meal);
      }
  </code></pre>
  
  <p>The MealRepository Class extends the JPARepository.</p>
  
  <p>Whenever I want to post something into my entity like:</p>
  
  <pre><code>{
      "id": 10,
      "name": "Test",
      "price": 3.50,
      "type": "with Meat"
  }
  </code></pre>
  
  <p>the following error appears: 
  <code>"could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"</code></p>
  
  <p>Adding via INSERT INTO works as usual.</p>