1
Package com.bjsxt.hibernate;
Import Java.util.HashSet;
Import Java.util.Set;
Import javax.persistence.Entity;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.Id;
Import Javax.persistence.JoinColumn;
Import javax.persistence.JoinTable;
Import Javax.persistence.ManyToMany;
@Entity public class Student {private int id;
private String name;
Private set<course> courses = new hashset<course> ();
@ManyToMany @JoinTable (name= "Score", joincolumns= @JoinColumn (name= "student_id", referencedcolumnname= "id"), inversejoincolumns= @JoinColumn (name= "course_id", referencedcolumnname= "id")) public set<course> getcourses ()
{return courses;
public void setcourses (set<course> courses) {this.courses = courses;
@Id @GeneratedValue public int getId () {return Id;
The public void setId (int id) {this.id = ID;
Public String GetName () {return name;
public void SetName (String name) {this.name = name;
}
}
2
Package com.bjsxt.hibernate;
Import javax.persistence.Entity;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.Id;
Import Javax.persistence.JoinColumn;
Import Javax.persistence.ManyToOne;
Import javax.persistence.Table;
@Entity
@Table (name= "score") public
class score {
private int id;
private int score;
Private Student Student;
Private Course Course;
@Id
@GeneratedValue Public
int getId () {return
Id;
}
public void setId (int id) {
this.id = ID;
}
public int Getscore () {return
score;
}
public void SetScore (int score) {
this.score = score;
}
@ManyToOne
@JoinColumn (name= "student_id") public
Student Getstudent () {return
student;
}
public void Setstudent (Student Student) {
this.student = Student;
}
@ManyToOne
@JoinColumn (name= "course_id") public
Course GetCourse () {return
course;
}
public void Setcourse (Course Course) {
this.course = Course;
}
}
3
Package com.bjsxt.hibernate;
Import javax.persistence.Entity;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.Id;
@Entity public
class Course {
private int id;
private String name;
@Id
@GeneratedValue 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;
}
}