From 4e560b9d361299ac27299a8e7083d8c6c63def1f Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 25 May 2020 21:10:19 +0200 Subject: [PATCH] Add cascading delete for connected entities --- backend/src/main/java/de/hft/geotime/entities/TimeRecord.java | 3 +++ .../main/java/de/hft/geotime/entities/TimetrackAccount.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java b/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java index ef08904..4af9a04 100644 --- a/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java +++ b/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java @@ -3,6 +3,8 @@ package de.hft.geotime.entities; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import javax.persistence.*; import java.time.LocalDateTime; @@ -19,6 +21,7 @@ public class TimeRecord { private long id; @ManyToOne + @OnDelete(action = OnDeleteAction.CASCADE) private TimetrackAccount account; @Column(columnDefinition = "TIMESTAMP") diff --git a/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java b/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java index bdec014..af3b5ba 100644 --- a/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java +++ b/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonBackReference; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import javax.persistence.*; @@ -21,6 +23,7 @@ public class TimetrackAccount { private String description; @ManyToOne + @OnDelete(action = OnDeleteAction.CASCADE) private TimetrackUser user; }