From c17b6df3b5232be5fc638ffadc8a751cf7dbebd1 Mon Sep 17 00:00:00 2001 From: omenem Date: Mon, 23 Mar 2020 17:53:22 +0100 Subject: [PATCH] delete cascade no more --- .../usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java index e192015..d06bece 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java @@ -6,6 +6,7 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.OneToMany; +import javax.persistence.PreRemove; /** Represents a generic dimmer input device */ @Entity @@ -32,4 +33,11 @@ public abstract class Dimmer extends InputDevice { public void addDimmableLight(DimmableLight dimmableLight) { lights.add(dimmableLight); } + + @PreRemove + private void removeLightsFromDimmer() { + for (DimmableLight dl : getOutputs()) { + dl.setDimmerId(null); + } + } }