Commit bc2ff294 by Juho Juopperi

cascades

1 parent 6d882242
...@@ -6,6 +6,7 @@ import java.io.Serializable; ...@@ -6,6 +6,7 @@ import java.io.Serializable;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
...@@ -42,7 +43,7 @@ public class Poll extends GenericEventChild implements Serializable { ...@@ -42,7 +43,7 @@ public class Poll extends GenericEventChild implements Serializable {
@Column(name = "description", nullable = true) @Column(name = "description", nullable = true)
private String description; private String description;
@OneToMany(mappedBy = "poll", fetch = FetchType.EAGER) @OneToMany(mappedBy = "poll", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<PollQuestion> questions; private List<PollQuestion> questions;
public Poll() { public Poll() {
......
...@@ -2,6 +2,7 @@ package fi.insomnia.bortal.model; ...@@ -2,6 +2,7 @@ package fi.insomnia.bortal.model;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
...@@ -26,7 +27,7 @@ public class PollQuestion extends GenericEventChild { ...@@ -26,7 +27,7 @@ public class PollQuestion extends GenericEventChild {
@ManyToOne @ManyToOne
private Poll poll; private Poll poll;
@OneToMany(mappedBy = "question") @OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
private List<PossibleAnswer> answers; private List<PossibleAnswer> answers;
@Lob @Lob
...@@ -41,11 +42,12 @@ public class PollQuestion extends GenericEventChild { ...@@ -41,11 +42,12 @@ public class PollQuestion extends GenericEventChild {
public String getQuestion() { public String getQuestion() {
return question; return question;
} }
public boolean isFreeText()
{ public boolean isFreeText() {
return (answers.size() == 1 && answers.get(0).isText()); return (answers.size() == 1 && answers.get(0).isText());
} }
public void setQuestion(String question) {
public void setQuestion(String question) {
this.question = question; this.question = question;
} }
......
...@@ -2,6 +2,7 @@ package fi.insomnia.bortal.model; ...@@ -2,6 +2,7 @@ package fi.insomnia.bortal.model;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
...@@ -33,8 +34,8 @@ public class PossibleAnswer extends GenericEventChild { ...@@ -33,8 +34,8 @@ public class PossibleAnswer extends GenericEventChild {
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne @ManyToOne
private PollQuestion question; private PollQuestion question;
@OneToMany(mappedBy="choice") @OneToMany(mappedBy = "choice", cascade = CascadeType.ALL)
private List<PollAnswer> answers; private List<PollAnswer> answers;
public String getAnswer() { public String getAnswer() {
...@@ -84,6 +85,5 @@ public class PossibleAnswer extends GenericEventChild { ...@@ -84,6 +85,5 @@ public class PossibleAnswer extends GenericEventChild {
public void setAnswers(List<PollAnswer> answers) { public void setAnswers(List<PollAnswer> answers) {
this.answers = answers; this.answers = answers;
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!