diff --git a/src/main/java/info/bukova/isspst/data/Requirement.java b/src/main/java/info/bukova/isspst/data/Requirement.java index 0d8d222d..36edec15 100644 --- a/src/main/java/info/bukova/isspst/data/Requirement.java +++ b/src/main/java/info/bukova/isspst/data/Requirement.java @@ -16,7 +16,7 @@ import javax.persistence.Table; @Table(name = "REQUIREMENT") public class Requirement extends RequirementBase { - @OneToMany(fetch = FetchType.EAGER, mappedBy = "requirement", cascade = CascadeType.ALL) + @OneToMany(fetch = FetchType.EAGER, mappedBy = "requirement", cascade = CascadeType.ALL, orphanRemoval = true) private List items; @Column(name = "DELIVERYDATE") @@ -37,6 +37,12 @@ public class Requirement extends RequirementBase { return items; } + + public void addItem(RequirementItem item) + { + item.setRequirement(this); // nutné nastavit kvůli obousměrné vazbě. Na položce v DB se jinak nenastaví ID hlavního záznamu + items.add(item); + } public void setItems(List items) { diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index 8b276556..b55f8607 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -184,7 +184,7 @@ public class RequirementForm extends FormViewModel } this.setSelectedItem(item); - this.getDataBean().getItems().add(item); + this.getDataBean().addItem(item); this.setSelItemIndex(this.getDataBean().getItems().indexOf(item)); } @@ -277,7 +277,7 @@ public class RequirementForm extends FormViewModel item.setMunit(null); this.setSelectedItem(item); - this.getDataBean().getItems().add(item); + this.getDataBean().addItem(item); this.setSelItemIndex(this.getDataBean().getItems().indexOf(item)); } }