我有两个实体,相关如下
@Entity
@Table(name = "APPOINTMENT")
public class Appointment {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long codeAp;
@ManyToOne(fetch = FetchType.EAGER)
, @OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "codeP")
private Patient patient;
//attributes
//getters and setters
//constructors
@Entity
@Table(name = "PATIENT")
public class Patient {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long codeP;
//attributes
//getters and setters
//constructors
Run Code Online (Sandbox Code Playgroud)
我正在使用JpaRepository删除方法。数据库中的表PATIENT和APPOINTMENT之间有一个约束,当我删除Patient时,我想删除孤儿。我添加了@OnDelete休眠注释,但是它对我不起作用!你能告诉我为什么吗?我想保持这种单向关系,请您帮我一下?