I have two objects related as below
@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;
@Entity
@Table(name = "PATIENT")
public class Patient {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long codeP;
I am using the JpaRepository removal method. There is a restriction between the PATIENT and PURPOSE tables in the database, I want to remove orphans when I delete the Patient. I added the @OnDelete hibernate annotation, but for me this does not work! Could you tell me why? I want to maintain this one-way relationship, could you help me with this?
source
share