Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package be.hi10.learning.entities;
- import java.io.Serializable;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.Table;
- @Entity
- @Table(name = "answers")
- public class Answer implements Serializable{
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE)
- private Long id;
- private String answer;
- // @ManyToOne
- @JoinColumn(name = "questionId")
- private Question question;
- private boolean isCorrect;
- public Answer(Long id, String answer, Question question, boolean isCorrect) {
- this.id=id;
- this.answer=answer;
- this.question=question;
- this.isCorrect=isCorrect;
- }
- public Answer() {
- }
- public Long getId() {
- return this.id;
- }
- public String getAnswer() {
- return this.answer;
- }
- public boolean getCorrect() {
- return this.isCorrect;
- }
- public Question getQuestion() {
- return this.question;
- }
- public void setQuestion(Question question) {
- this.question = question;
- }
- public boolean isCorrect() {
- return isCorrect;
- }
- public void setCorrect(boolean isCorrect) {
- this.isCorrect = isCorrect;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public void setAnswer(String answer) {
- this.answer = answer;
- }
- }
- --------------------------------------------------------------------------------------------------------------------------
- package be.hi10.learning.entities;
- import java.io.Serializable;
- import java.util.List;
- import javax.persistence.Entity;
- import javax.persistence.FetchType;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import com.fasterxml.jackson.annotation.JsonIgnore;
- import be.hi10.learning.enums.QuestionType;
- @Entity
- @Table(name = "questions")
- public class Question implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE)
- private Long questionId;
- private String question;
- // @JsonIgnore
- @OneToMany(mappedBy="question", fetch=FetchType.EAGER)
- private List<Answer> answers;
- private QuestionType type;
- // @JsonIgnore
- // @ManyToOne
- @JoinColumn(name = "categoryId")
- private Category category;
- public Question (String question, List<Answer> answers) {
- this.question = question;
- this.answers = answers;
- }
- public Question () {
- }
- public Long getId() {
- return this.questionId;
- }
- public String getQuestion() {
- return this.question;
- }
- public void setQuestion(String question) {
- this.question = question;
- }
- public List<Answer> getAnswers() {
- return this.answers;
- }
- public void setAnswer(List<Answer> answers) {
- this.answers = answers;
- }
- public void addAnswer(List<Answer> answers) {
- answers.forEach(a -> this.answers.add(a));
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- return true;
- }
- public QuestionType getType() {
- return type;
- }
- public void setType(QuestionType type) {
- this.type = type;
- }
- public Category getCategory() {
- return category;
- }
- public void setCategory(Category category) {
- this.category = category;
- }
- }
- --------------------------------------------------------------------------------------------------
- package be.hi10.learning.entities;
- import java.io.Serializable;
- import java.util.List;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- @Entity
- @Table(name = "categories")
- public class Category implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE)
- private Long categoryId;
- @OneToMany ( mappedBy = "category" )
- private List<Question> questions;
- private String category;
- public Category(Long categoryId, String category, List<Question> questions ) {
- this.categoryId = categoryId;
- this.category = category;
- this.questions = questions;
- }
- public Category() {
- }
- public Long getCategoryId() {
- return categoryId;
- }
- public void setCategoryId(Long categoryId) {
- this.categoryId = categoryId;
- }
- public String getCategory() {
- return category;
- }
- public void setCategory(String category) {
- this.category = category;
- }
- public List<Question> getQuestions() {
- return questions;
- }
- public void setQuestions(List<Question> questions) {
- this.questions = questions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement