日期:2014-05-19  浏览次数:20741 次

使用JPA标注,我的一对多关系没用关联映射为什么还报错?
这个是我的类大概:
  @Entity
  @Table(name = "CLASSID", schema = "SCOTT")
  public class Classid implements java.io.Serializable {
private static final long serialVersionUID = 3212644133804644683L;
private Integer id;
  private Set<Exam> exams; private Set<Classid> classids = new HashSet<Classid>(0);
private Set<Student> students = new HashSet<Student>(0);

public Classid() {
}

  public Classid(Integer id,String name){
  this.setId(id);
  }
@Id
@SequenceGenerator(name = "seq_classid")
@Column(name = "ID", unique = true, nullable = false, scale = 0)
public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;

}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "classid")
public Set<Classid> getClassids() {
return this.classids;
}

public void setClassids(Set<Classid> classids) {
this.classids = classids;
}

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "classid")
public Set<Student> getStudents() {
return this.students;
}
public void setStudents(Set<Student> students) {
this.students = students;
}

  public Set<Exam> getExams() {
return this.exams;
}
public void setExams(Set<Exam> exams) {
this.exams= exams;
}
}

我没用关联映射,为什么还是会报错啊,报的错误为:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: CLASSID, for columns: [org.hibernate.mapping.Column(exams)]

------解决方案--------------------
可能是之前生成的class文件没有清理干净。然后,就直接使用了之前生成的class文件,但是,对应是数据库schma已经被更新而没有了这些列,导致映射失败。在使用maven之类的工具时会出现这些问题,我遇到过。