From f3680844643f11fa6403e32436798bcf32bfc95e Mon Sep 17 00:00:00 2001 From: omenem Date: Mon, 23 Mar 2020 18:31:46 +0100 Subject: [PATCH] delete cascade no more in switch --- .../usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java index d819dfe..ed6f38d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java @@ -5,6 +5,7 @@ import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.OneToMany; +import javax.persistence.PreRemove; /** A switch input device */ @Entity @@ -51,4 +52,11 @@ public class Switch extends InputDevice { public Set getOutputs() { return switchables; } + + @PreRemove + private void removeSwitchable() { + for (Switchable s : getOutputs()) { + s.setSwitchId(null); + } + } }