title: Deleting entity in Spring JPA
body: <p>There are two entities with relation @ManyToOne and @OneToMany (Categories and Products). When I enabeling (cascade=CascadeType.ALL) one record in Products pulls for deleting one Category, and that is BAD. What must be do for this entities that result is only deleting occurs in one place(Table) without cascade(related) delete for another reference??? I am using Spring 5.1.5 (not Spring Boot) 
  Thank you!</p>
  
  <p>SPRING 5 / TOMCAT 9 / JACKSON-DATABIND / spring-data-jpa 2.1.5 / persistence-api 1.0.2 / Hibernate-core 5.4.1</p>
  
  <p>@Entity
  public class Category {</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  @Column(name="CAT_ID")
  private Long id;
  
  @Column(name="CAT_NAME")
  private String name;
  
  @JsonManagedReference
  @OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER)
  @JoinColumn(name="CAT_ID")
  @OrderBy
  private Set&lt;Product&gt; products = new HashSet&lt;&gt;();
  
  public Long getId() {
      return id;
  }
  </code></pre>
  
  <p>@Entity
  public class Product {</p>
  
  <pre><code>    @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name="PRODUCT_ID")
      private Long id;
  
      @Column(name="PRODUCT_NAME")
      private String name;
  
      @JsonBackReference
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name="CAT_ID")
      private Category category;
  
      public Long getId() {
          return id;
      }
  </code></pre>
  
  <p>@RequestMapping(value="/categories/{categoryId}/products/{productId}", method=RequestMethod.DELETE)
      public ResponseEntity deleteById(@PathVariable Long categoryId, @PathVariable Long productId) {
          productService.deleteProductById(productId);
          return new ResponseEntity&lt;>(HttpStatus.OK);
      }</p>
  
  <pre><code>@Transactional
  @Override
  public void deleteProductById(Long productId) {
      // TODO Auto-generated method stub
      productRepository.deleteById(productId);
  
  }
  </code></pre>