diff --git a/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java b/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java index 8c543d6..7e1f600 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java +++ b/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java @@ -3,6 +3,8 @@ package com.loafle.overflow.module.sensor.model; import com.loafle.overflow.meta.model.MetaCrawler; import com.loafle.overflow.meta.model.MetaSensorStatus; import com.loafle.overflow.module.target.model.Target; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import javax.persistence.*; import java.util.Date; @@ -61,6 +63,7 @@ public class Sensor { } @ManyToOne + @OnDelete(action = OnDeleteAction.CASCADE) @JoinColumn(name = "TARGET_ID", nullable = false) public Target getTarget() { return target; diff --git a/src/main/java/com/loafle/overflow/module/sensor/model/SensorItem.java b/src/main/java/com/loafle/overflow/module/sensor/model/SensorItem.java index 9ca3145..51823ed 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/model/SensorItem.java +++ b/src/main/java/com/loafle/overflow/module/sensor/model/SensorItem.java @@ -1,6 +1,8 @@ package com.loafle.overflow.module.sensor.model; import com.loafle.overflow.meta.model.MetaSensorItem; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import javax.persistence.*; import java.util.Date; @@ -28,6 +30,7 @@ public class SensorItem { @ManyToOne @JoinColumn(name = "SENSOR_ID", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) public Sensor getSensor() { return this.sensor; } diff --git a/src/main/java/com/loafle/overflow/module/target/model/Target.java b/src/main/java/com/loafle/overflow/module/target/model/Target.java index 91e6c89..c758ee7 100644 --- a/src/main/java/com/loafle/overflow/module/target/model/Target.java +++ b/src/main/java/com/loafle/overflow/module/target/model/Target.java @@ -2,6 +2,8 @@ package com.loafle.overflow.module.target.model; import com.loafle.overflow.module.infra.model.Infra; import com.loafle.overflow.module.probe.model.Probe; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import javax.persistence.*; import java.util.Date; @@ -40,6 +42,7 @@ public class Target { @ManyToOne @JoinColumn(name = "PROBE_ID", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) public Probe getProbe() { return probe; } diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 70fea7d..9b2079c 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -275,7 +275,7 @@ INSERT INTO public.sensor (id,crawler_input_items,create_date,description,crawle INSERT INTO public.sensor (id,crawler_input_items,create_date,description,crawler_id,status,target_id) VALUES ( 2,NULL,'2017-06-26 20:19:07.074','My sensor',1,1,1); -INSERT INTO public.sensor_item (id,create_date,item_id,sensor_id) VALUES ( +INSERT INTO public.sensor_item (id,create_date,item_id,sensor_id) VALUES ( 1,'2017-06-26 20:21:16.626',1,1); INSERT INTO public.sensor_item (id,create_date,item_id,sensor_id) VALUES ( 2,'2017-06-26 20:21:50.988',2,2); \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java b/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java index 769b124..edf252a 100644 --- a/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java +++ b/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java @@ -16,7 +16,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Date; import java.util.List; -@Ignore @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) public class TargetDAOTest { @@ -25,6 +24,7 @@ public class TargetDAOTest { private TargetDAO repo; @Test + @Ignore public void create() { Target t = new Target(); t.setCreateDate(new Date()); @@ -43,6 +43,7 @@ public class TargetDAOTest { } @Test + @Ignore public void list() { Probe p = new Probe(); @@ -51,5 +52,11 @@ public class TargetDAOTest { Assert.assertNotNull(list); } - + @Test + @Ignore + public void delete() { + Target t = new Target(); + t.setId(1); + repo.delete(t); + } } \ No newline at end of file