cascade delete
This commit is contained in:
parent
ab91e2e648
commit
cc21e6ce6d
|
@ -3,6 +3,8 @@ package com.loafle.overflow.module.sensor.model;
|
||||||
import com.loafle.overflow.meta.model.MetaCrawler;
|
import com.loafle.overflow.meta.model.MetaCrawler;
|
||||||
import com.loafle.overflow.meta.model.MetaSensorStatus;
|
import com.loafle.overflow.meta.model.MetaSensorStatus;
|
||||||
import com.loafle.overflow.module.target.model.Target;
|
import com.loafle.overflow.module.target.model.Target;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -61,6 +63,7 @@ public class Sensor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
@JoinColumn(name = "TARGET_ID", nullable = false)
|
@JoinColumn(name = "TARGET_ID", nullable = false)
|
||||||
public Target getTarget() {
|
public Target getTarget() {
|
||||||
return target;
|
return target;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.loafle.overflow.module.sensor.model;
|
package com.loafle.overflow.module.sensor.model;
|
||||||
|
|
||||||
import com.loafle.overflow.meta.model.MetaSensorItem;
|
import com.loafle.overflow.meta.model.MetaSensorItem;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -28,6 +30,7 @@ public class SensorItem {
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "SENSOR_ID", nullable = false)
|
@JoinColumn(name = "SENSOR_ID", nullable = false)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
public Sensor getSensor() {
|
public Sensor getSensor() {
|
||||||
return this.sensor;
|
return this.sensor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.loafle.overflow.module.target.model;
|
||||||
|
|
||||||
import com.loafle.overflow.module.infra.model.Infra;
|
import com.loafle.overflow.module.infra.model.Infra;
|
||||||
import com.loafle.overflow.module.probe.model.Probe;
|
import com.loafle.overflow.module.probe.model.Probe;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -40,6 +42,7 @@ public class Target {
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "PROBE_ID", nullable = false)
|
@JoinColumn(name = "PROBE_ID", nullable = false)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
public Probe getProbe() {
|
public Probe getProbe() {
|
||||||
return probe;
|
return probe;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 (
|
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);
|
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);
|
1,'2017-06-26 20:21:16.626',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 (
|
||||||
2,'2017-06-26 20:21:50.988',2,2);
|
2,'2017-06-26 20:21:50.988',2,2);
|
|
@ -16,7 +16,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class})
|
@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class})
|
||||||
public class TargetDAOTest {
|
public class TargetDAOTest {
|
||||||
|
@ -25,6 +24,7 @@ public class TargetDAOTest {
|
||||||
private TargetDAO repo;
|
private TargetDAO repo;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void create() {
|
public void create() {
|
||||||
Target t = new Target();
|
Target t = new Target();
|
||||||
t.setCreateDate(new Date());
|
t.setCreateDate(new Date());
|
||||||
|
@ -43,6 +43,7 @@ public class TargetDAOTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void list() {
|
public void list() {
|
||||||
|
|
||||||
Probe p = new Probe();
|
Probe p = new Probe();
|
||||||
|
@ -51,5 +52,11 @@ public class TargetDAOTest {
|
||||||
Assert.assertNotNull(list);
|
Assert.assertNotNull(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void delete() {
|
||||||
|
Target t = new Target();
|
||||||
|
t.setId(1);
|
||||||
|
repo.delete(t);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user