@Entity
public class Teacher {
@Id
@Column(name="teacher_id")
private int id;
@Column(name="teacher_name")
private String name;
@Column(name="teacher_phone")
private String phoneNumber;
private List<Course> courses;
public Teacher() {
courses = new ArrayList<>();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@OneToMany(mappedBy="teacher")
public List<Course> getCourses() {
return courses;
}
}
@Entity
public class Teacher {
@Id
@Column(name="teacher_id")
private int id;
@Column(name="teacher_name")
private String name;
@Column(name="teacher_phone")
private String phoneNumber;
private List<Course> courses;
public Teacher() {
courses = new ArrayList<>();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@OneToMany(mappedBy="teacher")
public List<Course> getCourses() {
return courses;
}
}
@Entity
public class Course {
@Id
@Column(name="course_id")
private int id;
@Column(name="course_name")
private String name;
@Column(name="course_schedule")
private String schedule;
private Teacher teacher;
public Course() {
}
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name="teacher_id")
public Teacher getTeacher() {
return teacher;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSchedule() {
return schedule;
}
public void setSchedule(String schedule) {
this.schedule = schedule;
}
}
@Entity
public class Course {
@Id
@Column(name="course_id")
private int id;
@Column(name="course_name")
private String name;
@Column(name="course_schedule")
private String schedule;
private Teacher teacher;
public Course() {
}
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name="teacher_id")
public Teacher getTeacher() {
return teacher;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSchedule() {
return schedule;
}
public void setSchedule(String schedule) {
this.schedule = schedule;
}
}