If you look closely at your stacktrace, you will see
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.Question.examId references an unknown entity: long
So this field
@ManyToOne
private long examId;
is causing the problem. @ManyToOne
has a paramater targetEntity
which says:
(Optional) The entity class that is the target of the association.
Defaults to the type of the field or property that stores the association.
Since you haven't provided that parameter, it defaults to long
, which is not a managed Entity
.
You'll probably want to use
@ManyToOne(targetEntity = Exam.class)
private long examId;
otherwise it won't know what to map to. Or even better
@ManyToOne
private Exam exam;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…