There was a problem:
When a child is deleted, the parent is deleted. How to fix it.
The Worker has a List of Positions (A Position is a separate entity). How to delete a post from a Worker when deleting a post.
All heters and setters and designers removed. I use Spring Boot + Spring Data + Hibernate
This is Worker
@Entity @Table(name = "worker") @Inheritance(strategy = InheritanceType.JOINED) public class Worker implements Serializable { @Id @GeneratedValue @Column(name = "id") private Long id; @Column(name = "firstName", length = 256) private String firstName; @Column(name = "lastName", length = 256) private String lastName; @Column(name = "email") private String email; @Column(name = "phoneNumber") private Long phoneNumber; @Column(name = "shiftSalary", nullable = true) private Long shiftSalary; @ManyToMany(cascade = { CascadeType.REMOVE }, mappedBy="workerList") private List<Position> allPosition; @Column(name = "countShift", nullable = true) private Long countShift; @Column(name = "salary", nullable = true) private Long salary; This Position
@Entity @Table(name = "position") public class Position { @Id @GeneratedValue @Column(name = "id") private Long id; @Column(name = "jobName") private String jobName; @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST }) @JoinTable(name = "permissions_allPosition", joinColumns = {@JoinColumn(name = "position_id")}, inverseJoinColumns = {@JoinColumn(name = "worker_id")}) private List<Worker> workerList;