hibernate多对多单向(双向)关系映射
package yingjun.model;import java.util.HashSet;import java.util.Set;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.ManyToMany;@Entitypublic class Course {private int cid;private String name;private Set<Student> students=new HashSet<Student>();@Id@GeneratedValuepublic int getCid() {return cid;}public void setCid(int cid) {this.cid = cid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public void setStudents(Set<Student> students) {this.students = students;}@ManyToMany(mappedBy="courses")public Set<Student> getStudents() {return students;}}
?生成的建表语句和多对多单向关联的一样(在数据库他们的表现一样)
?
1 楼 Mybeautiful 2013-03-21 几篇hibernate的文章都写的很好。说的很少,但说的很清楚。