fix for remove event

This commit is contained in:
Anton Romanov 2018-11-19 08:21:22 +04:00
parent 2dc0b4e27c
commit 58299d749d
2 changed files with 16 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
@ -66,6 +67,10 @@ public class Event extends BaseEntity {
@JoinColumn(name = "child_id") @JoinColumn(name = "child_id")
private Event child; private Event child;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "child_id")
private List<Event> parents;
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -137,4 +142,12 @@ public class Event extends BaseEntity {
public void setChild(Event child) { public void setChild(Event child) {
this.child = child; this.child = child;
} }
public List<Event> getParents() {
return parents;
}
public void setParents(List<Event> parents) {
this.parents = parents;
}
} }

View File

@ -57,8 +57,9 @@ public class EventService {
} }
@Transactional @Transactional
public void delete(Integer timelineId) { public void delete(Integer eventId) {
Event event = eventRepository.findOne(timelineId); Event event = eventRepository.findOne(eventId);
event.setParents(null);
eventRepository.delete(event); eventRepository.delete(event);
} }