我创建了一些实体但我在服务器上运行时出现以下错误:
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
[spring-orm-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564) [spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE] ......还有35个 引起:org.hibernate.AnnotationException:@OneToOne或@ManyToOne on ..... entities.exams.answer.questionId引用一个未知实体: ..... entities.exams.question
这是实体的代码
@Entity
@Table(schema="..",name = "exam_answers")
@NamedQueries({
@NamedQuery(name = "answer.findAll", query = "SELECT s FROM answer s"),
@NamedQuery(name = "answer.findByanswerId", query = "SELECT s FROM answer s WHERE s.answerId = :answerId"),
@NamedQuery(name = "answer.findByquestionId", query = "SELECT s FROM answer s WHERE s.questionId = :questionId"),
@NamedQuery(name = "answer.findByanswer", query = "SELECT s FROM answer s WHERE s.answer = :answer") })
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "exams")
public class answer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = Generationquestion.IDENTITY)
@Basic(optional = false)
@Column(name = "answer_id")
private Integer answerId;
@JoinColumn(name = "question_id")
@ManyToOne(optional = false)
private question questionId;
@JoinColumn(name = "exam_id", referencedColumnName = "exam_id")
@ManyToOne(optional = false)
private exam examId;
@Size(max = 500)
@Column(name = "answer")
private String answer;
public answer() {
}
public answer(Integer answerId) {
this.answerId = answerId;
}
...SETTERS AND GETTERS...
}
@Entity
@Table(schema="..",name = "question")
@NamedQueries({
@NamedQuery(name = "question.findAll", query = "SELECT s FROM question s"),
@NamedQuery(name = "question.findByquestionId", query = "SELECT s FROM question s WHERE s.questionId = :questionId"),
@NamedQuery(name = "question.findByLabel", query = "SELECT s FROM question s WHERE s.label = :label"),
@NamedQuery(name = "question.findByquestion", query = "SELECT s FROM question s WHERE s.question = :question"),
@NamedQuery(name = "question.findByInputquestion", query = "SELECT s FROM question s WHERE s.inputquestion = :inputquestion"),
@NamedQuery(name = "question.findByOptions", query = "SELECT s FROM question s WHERE s.options = :options")})
public class question implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = Generationquestion.IDENTITY)
@Basic(optional = false)
@Column(name = "question_id")
private Integer questionId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 500)
@Column(name = "label")
private String label;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 20)
@Column(name = "question")
private String question;
@Size(max = 50)
@Column(name = "input_question")
private String inputquestion;
@Size(max = 500)
@Column(name = "options")
private String options;
public question() {
}
public question(Integer questionId) {
this.questionId = questionId;
}
答案 0 :(得分:0)
以下是错误原因
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on
.....entities.exams.answer.questionId references an unknown entity:
.....entities.exams.question
您是否已将entities.exams.question
添加到hibernate配置?
还有几点:
questionId
,因为这会令人困惑。单词id
应该只用于Long / Integer属性(可能偶尔使用String)