Spring Data Repository does not delete ManyToOne Entity

前端 未结 6 631
陌清茗
陌清茗 2021-01-30 13:39

I\'m am currently trying to use a Spring Data repository to delete some of my entities. The delete call works without any exceptions/error messages, but the entity is not delete

6条回答
  •  天涯浪人
    2021-01-30 14:04

    The problem seems to be that you are using cascade=CascadeType.ALL, which also includes CascadeType.PERSIST. CascadeType.PERSIST means that the child entity is completely managed by the parent and you cannot delete it directly. In order to delete you just need to remove it from the parent.

    You could just add the other CascadeTypes instead of all. e.g CascadeType.REMOVE, if the only thing you would want is to remove the child if the parent is removed.

提交回复
热议问题