org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.Ques#tion.examId references an unknown entity: long

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;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)