title: How to send POST request with Many-to-many relationship in Spring?
body: <p>I'm trying to add a order with equipment list, here's my entities:</p>
  
  <p>the order entity</p>
  
  <pre><code> @Entity @Table(name = "orders") public class Order extends Ticket{
  @OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
  private Set&lt;OrderEquipment&gt; orderEquipments = new HashSet&lt;&gt;();}
  </code></pre>
  
  <p>the equipment entity</p>
  
  <pre><code> @Entity @Table(name = "equipments") public class Equipment extends DateAudit {
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  
  @NotBlank
  @Size(max = 30)
  private String name;
  
  
  @NotNull
  private Long nbr_piece ;
  
  @OneToMany(mappedBy = "equipment", cascade = CascadeType.ALL, orphanRemoval = true)
  private Set&lt;OrderEquipment&gt; orderEquipments = new HashSet&lt;&gt;();}
  </code></pre>
  
  <p>and the order_equipment entity</p>
  
  <pre><code>@Entity @Table(name = "order_equipment") public class OrderEquipment extends DateAudit { @Id
  @ManyToOne
  @JoinColumn(name = "order_id")
  private Order order;
  
  @Id
  @ManyToOne
  @JoinColumn(name = "equipment_id")
  private Equipment equipment;
  
  @NotBlank
  @Column(name = "quantity")
  private Long quantity;}
  </code></pre>
  
  <p>here is the add function in the orderController</p>
  
  <pre><code> @PostMapping("/orders")
  public Order createOrder(@Valid @RequestBody Order Order){
   Order.setObservateurEmail(Order.getObservateurEmail());
   Order.setObject(Order.getObject());
   Order.setDescription(Order.getDescription());      
   return orderRepository.save(Order);          
  } 
  </code></pre>