当前位置: 代码迷 >> Web开发 >> Illegal attempt to 地图 a non collection as a @OneToMany, @ManyToMany or @Collect
  详细解决方案

Illegal attempt to 地图 a non collection as a @OneToMany, @ManyToMany or @Collect

热度:934   发布时间:2013-08-09 15:16:24.0
Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @Collect
三个实体类Questions、survey和results。questions和Survey是多对多的关系,results是中间表。
Questions类如下:
package com.bean;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

@Entity
public class Questions {
private int q_id;//问题主键ID
private Set<Survey> survey=new HashSet<Survey>();//外键,属于哪一个问卷
private QuestionType q_type;//问题类型
private AnswerSheet as;//答卷表
private String q_head;//问题题目
private String q_body;//问题主体
private String q_key;//预留字段,如果是网上答卷,则是答案
private String q_remarks;// 预留字段,备注
private int q_number;//选项个数
@Id
@GeneratedValue
    public int getQ_id() {
return q_id;
}
public void setQ_id(int q_id) {
this.q_id = q_id;
}
@ManyToMany
(mappedBy="question")
public Set<Survey> getSurvey() {
return survey;
}
public void setSurvey(Set<Survey> survey) {
this.survey = survey;
}

public String getQ_head() {
return q_head;
}
public void setQ_head(String q_head) {
this.q_head = q_head;
}
public String getQ_body() {
return q_body;
}
public void setQ_body(String q_body) {
this.q_body = q_body;
}
public String getQ_key() {
return q_key;
}
public void setQ_key(String q_key) {
this.q_key = q_key;
}
public String getQ_remarks() {
return q_remarks;
}
public void setQ_remarks(String q_remarks) {
this.q_remarks = q_remarks;
}
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn (name="qt_id")
public QuestionType getQ_type() {
return q_type;
}
public void setQ_type(QuestionType q_type) {
this.q_type = q_type;
}
@ManyToOne
@JoinColumn(name="as_id")
public AnswerSheet getAs() {
return as;
}
public void setAs(AnswerSheet as) {
this.as = as;
  相关解决方案