There are two playlist(id, user, title) tables playlist(id, user, title) and playlist_content(id, playlist_id, melody_id) . It is necessary that when deleting a record from the playlist, all records from the playlist_content are deleted, while deleting nothing in the playlist_content table from the playlist (and no errors should appear). I did it like this: I put PlaylistContent cascade = CascadeType.REMOVE on the playlist field

 @ManyToOne(cascade = CascadeType.REMOVE) @JoinColumn(name = "playlist_id", nullable = false) private Playlist playlist; 

Will this work correctly?

    1 answer 1

    On the contrary, you need to add CascadeType.REMOVE to the playlist table ( Playlist entities):

     @Entity public class Playlist implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name="id") private int id; @Column(name="user") private String user; @Column(name="title") private String title; @OneToMany(cascade=CascadeType.REMOVE) @JoinColumn(name="id") private Set<PlaylistContent> playlist_contents; }