Created
July 23, 2012 02:01
-
-
Save fankay/3161666 to your computer and use it in GitHub Desktop.
Hibernate Annotation 中多对多的配置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@Table(name="t_student") | |
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE) | |
public class Student { | |
private int id; | |
private String name; | |
private Set<Teacher> teacherSet; | |
@Id | |
@GeneratedValue(strategy=GenerationType.IDENTITY) | |
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; | |
} | |
@ManyToMany | |
@JoinTable( | |
name="t_student_teacher", | |
joinColumns={@JoinColumn(name="studentid")}, | |
inverseJoinColumns={@JoinColumn(name="teacherid")} | |
) | |
public Set<Teacher> getTeacherSet() { | |
return teacherSet; | |
} | |
public void setTeacherSet(Set<Teacher> teacherSet) { | |
this.teacherSet = teacherSet; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@Table(name="t_teacher") | |
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE) | |
public class Teacher { | |
private int id; | |
private String name; | |
private List<Student> studentSet; | |
@Id | |
@GeneratedValue(strategy=GenerationType.IDENTITY) | |
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; | |
} | |
@ManyToMany(mappedBy="teacherSet") | |
public List<Student> getStudentSet() { | |
return studentSet; | |
} | |
public void setStudentSet(List<Student> studentSet) { | |
this.studentSet = studentSet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment