日期:2014-05-20 浏览次数:20674 次
package com.model; import java.util.HashSet; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; @Entity public class Teacher { private int id; private String name; private HashSet<Student> students = new HashSet<Student>(); @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; } @ManyToMany public HashSet<Student> getStudents() { return students; } public void setStudents(HashSet<Student> students) { this.students = students; } }
package com.model; import java.util.HashSet; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; @Entity public class Student { private int id; private String name; private HashSet<Teacher> teahcers = new HashSet<Teacher>(); @ManyToMany(mappedBy="students") public HashSet<Teacher> getTeahcers() { return teahcers; } public void setTeahcers(HashSet<Teacher> teahcers) { this.teahcers = teahcers; } @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; } }