From e889e0f45ad5cd8eecf4d430b200eda9a04b6add Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 24 Sep 2014 21:52:25 +0200 Subject: [PATCH] =?UTF-8?q?Opraveno=20ukl=C3=A1d=C3=A1n=C3=AD=20polo=C5=BE?= =?UTF-8?q?ek=20po=C5=BEadavk=C5=AF=20do=20datab=C3=A1ze.=20Z=20d=C5=AFvod?= =?UTF-8?q?u=20obousm=C4=9Brn=C3=A9=20vazby=20po=C5=BEadavek=20-=20polo?= =?UTF-8?q?=C5=BEka,=20se=20mus=C3=AD=20na=20polo=C5=BEce=20vkl=C3=A1dan?= =?UTF-8?q?=C3=A9=20do=20po=C5=BEadavku=20nastavit=20tento=20po=C5=BEadave?= =?UTF-8?q?k.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/info/bukova/isspst/data/Requirement.java | 8 +++++++- .../ui/main/orders/requirements/RequirementForm.java | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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)); } }