大哥们帮帮看看错在哪里 hibernate Annotation 老师 学生 的多对多双向
这是两个实体类,分别是学生和老师
这是错误信息
org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.model.Teacher.students
老师类
package com.model;import java.util.HashSet;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.ManyToMany;@Entitypublic 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;@Entitypublic 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; } }