title: How to update list of child entities when i have ManyToMany relationship (spring-boot/spring-data-jpa)?
body: <p>I have Product and Category entities. There is ManyToMany relationship between them and Product is relationship owner, so when I call action to create/save Product(with category1 and category2 for example) two queries are called:</p>
  
  <ol>
  <li>insert into Products...</li>
  <li>insert into ProductCategory...</li>
  </ol>
  
  <p>And that is expected behavior.</p>
  
  <p>But, when I add/remove come categories and try to call update(fetch product from db, set new values, and call save again) then these two queries are called:</p>
  
  <ol>
  <li>update Products...</li>
  <li>update Categories...</li>
  </ol>
  
  <p>MY GOAL is to update just "products" table, and update JOIN TABLE("ProductCategory").</p>
  
  <p>Here are related domain classes:</p>
  
  <pre><code>@Entity
  @Data
  @Table(name = "products")
  @EqualsAndHashCode(callSuper = false)
  public class Product extends BaseEntityAudit {
  
  @NotEmpty
  @Column(name = "name")
  private String name;
  
  @Column(name = "description")
  private String description;
  
  @NotEmpty
  @Column(name = "code")
  private String code;
  
  @NotNull
  @Column(name = "price")
  private Double price;
  
  @Column(name = "published", nullable = true)
  private boolean published;
  
  @OneToMany(mappedBy = "product")
  private List&lt;Order&gt; orders;
  
  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "ecommerce_id", nullable = false)
  private ECommerce eCommerce;
  
  @ManyToMany(fetch = FetchType.LAZY,
          cascade = { CascadeType.MERGE, CascadeType.REFRESH })
  @JoinTable(
          name = "CategoryProduct",
          joinColumns = { @JoinColumn(name = "product_id") },
          inverseJoinColumns = { @JoinColumn(name = "category_id") }
  )
  private List&lt;Category&gt; categories;
  }
  
  @Entity
  @Data
  @Table(name = "categories")
  @EqualsAndHashCode(callSuper = false)
  public class Category extends BaseEntityAudit {
  
  @Column(name = "name")
  private String name;
  
  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "ecommerce_id", nullable = false)
  private ECommerce eCommerce;
  
  @ManyToMany(mappedBy = "categories",
              cascade = { CascadeType.MERGE, CascadeType.REFRESH } )
  
  private List&lt;Product&gt; products;
  }
  </code></pre>
  
  <p>And this is service method which handles update request: </p>
  
  <pre><code>@Override
  public ProductResponse update(CreateUpdateProductRequest request,
                          String productId) throws ProductNotFoundException {
      Product product = productRepository.getOne(Long.valueOf(productId));
  
      productTransformer.productRequestToProduct(request, product);
      return productTransformer.productToProductResponse(
          productRepository.save(product));
  }
  </code></pre>
  
  <p>And CreateUpdateProductRequest to Product transformer:</p>
  
  <pre><code>public void productRequestToProduct(CreateUpdateProductRequest request, 
  Product product) {
      ECommerce eCommerce = new ECommerce();
      eCommerce.setId(Long.valueOf(request.getECommerceId()));
      product.setName(request.getName());
      product.setDescription(request.getDescription());
      product.setCode(request.getCode());
      product.setPrice(request.getPrice());
  
      product.setCategories(
          categoriesRequestToDomain(request.getCategoryIds()
      ));
      product.setECommerce(eCommerce);
  }
  </code></pre>
  
  <p>What should I do to keep records in JOIN TABLE(ProductCategory) up to date using just power of spring-data-jpa?</p>