Колледж
Код: Выделить всё
@Entity
public class College {
private int collegeId;
private String collegeName;
private List students;
@Id
@GeneratedValue
public int getCollegeId() {
return collegeId;
}
public void setCollegeId(int collegeId) {
this.collegeId = collegeId;
}
public String getCollegeName() {
return collegeName;
}
public void setCollegeName(String collegeName) {
this.collegeName = collegeName;
}
@OneToMany(targetEntity=Student.class, mappedBy="college", cascade=CascadeType.ALL, fetch=FetchType.EAGER )
public List getStudents() {
return students;
}
public void setStudents(List students) {
this.students = students;
}
}
Код: Выделить всё
@Entity
public class Student {
private int studentId;
private String studentName;
private College college;
@Id
@GeneratedValue
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
@ManyToOne
@JoinColumn(name="college_id")
public College getCollege() {
return college;
}
public void setCollege(College college) {
this.college = college;
}
}
Код: Выделить всё
College college = (College) session.get(College.class, id);
Код: Выделить всё
collegeОбъект Подробнее здесь: https://stackoverflow.com/questions/301 ... ot-working
Мобильная версия