|
| 1 | +package com.baeldung.manytomany.model; |
| 2 | + |
| 3 | +import java.time.LocalDateTime; |
| 4 | + |
| 5 | +import javax.persistence.Column; |
| 6 | +import javax.persistence.Entity; |
| 7 | +import javax.persistence.Id; |
| 8 | +import javax.persistence.JoinColumn; |
| 9 | +import javax.persistence.ManyToOne; |
| 10 | +import javax.persistence.Table; |
| 11 | + |
| 12 | +@Entity |
| 13 | +@Table(name = "course_registration") |
| 14 | +public class CourseRegistration { |
| 15 | + |
| 16 | + @Id |
| 17 | + @Column(name = "id") |
| 18 | + private Long id; |
| 19 | + |
| 20 | + @ManyToOne |
| 21 | + @JoinColumn(name = "student_id") |
| 22 | + private Student student; |
| 23 | + |
| 24 | + @ManyToOne |
| 25 | + @JoinColumn(name = "course_id") |
| 26 | + private Course course; |
| 27 | + |
| 28 | + @Column(name = "registered_at") |
| 29 | + private LocalDateTime registeredAt; |
| 30 | + |
| 31 | + @Column(name = "grade") |
| 32 | + private int grade; |
| 33 | + |
| 34 | + // additional properties |
| 35 | + |
| 36 | + public CourseRegistration() { |
| 37 | + } |
| 38 | + |
| 39 | + public Student getStudent() { |
| 40 | + return student; |
| 41 | + } |
| 42 | + |
| 43 | + public void setStudent(Student student) { |
| 44 | + this.student = student; |
| 45 | + } |
| 46 | + |
| 47 | + public Course getCourse() { |
| 48 | + return course; |
| 49 | + } |
| 50 | + |
| 51 | + public void setCourse(Course course) { |
| 52 | + this.course = course; |
| 53 | + } |
| 54 | + |
| 55 | + public LocalDateTime getRegisteredAt() { |
| 56 | + return registeredAt; |
| 57 | + } |
| 58 | + |
| 59 | + public void setRegisteredAt(LocalDateTime registeredAt) { |
| 60 | + this.registeredAt = registeredAt; |
| 61 | + } |
| 62 | + |
| 63 | + public int getGrade() { |
| 64 | + return grade; |
| 65 | + } |
| 66 | + |
| 67 | + public void setGrade(int grade) { |
| 68 | + this.grade = grade; |
| 69 | + } |
| 70 | + |
| 71 | + public Long getId() { |
| 72 | + return id; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public int hashCode() { |
| 77 | + final int prime = 31; |
| 78 | + int result = 1; |
| 79 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 80 | + return result; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public boolean equals(Object obj) { |
| 85 | + if (this == obj) |
| 86 | + return true; |
| 87 | + if (obj == null) |
| 88 | + return false; |
| 89 | + if (getClass() != obj.getClass()) |
| 90 | + return false; |
| 91 | + CourseRegistration other = (CourseRegistration) obj; |
| 92 | + if (id == null) { |
| 93 | + if (other.id != null) |
| 94 | + return false; |
| 95 | + } else if (!id.equals(other.id)) |
| 96 | + return false; |
| 97 | + return true; |
| 98 | + } |
| 99 | + |
| 100 | +} |
0 commit comments