2 years ago
#71120
MANU MISHRA
In @OneToMany mapping not able to fetch the associated object
public class Answers {
private int answerId;
private String answer;
@ManyToOne(fetch = FetchType.EAGER)
private Questions questions;
}
public class Questions {
@Id
private int questionId;
private String question;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "questions")
private List<Answers> answer;
}
Answers answers = session.get(Answers.class, 1234);
System.out.println(answers.getQuestions()); //giving null pointer exceptiom
while fetching answer I'm not getting the question object associated with it. while getting associated question with the answer I'm getting null pointer.
java
hibernate
one-to-many
0 Answers
Your Answer