Add cascading delete for connected entities

This commit is contained in:
Marcel Schwarz 2020-05-25 21:10:19 +02:00
parent 0d4eb694c9
commit 4e560b9d36
2 changed files with 6 additions and 0 deletions

View File

@ -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")

View File

@ -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;
}