0

I'm using Spring Data JPA, I have a Category object as following:

@Entity(name="category")
public class Category {

  @ManyToOne
  private Category supercategory;

  @OneToMany(mappedBy="supercategory")
  private List<Category> subcategories;

  // ...
}

Now, whenever I remove any supercategory the subcategories "supercategory_id" is not updated to NULL in MySQL.

I don't want to remove the subcategories, just to remove the relation, which is by nullifying the "supercategory_id" column in the DB.

Thanks.

Ja'afar Naddaf
  • 357
  • 4
  • 13
  • The answer is in the question. You need to nullify the supercategory field of the sub categories, since that's the field which is mapped to the supercategory_id column in the database. – JB Nizet May 19 '19 at 12:52
  • Have a look at this for more details https://stackoverflow.com/questions/9944137/have-jpa-hibernate-to-replicate-the-on-delete-set-null-functionality – samvel1024 May 19 '19 at 12:56

0 Answers0