JPA OneToMany:无法获得实体的 children

JPA OneToMany : Impossible to get the children of an entity

我有一个 class 问题和一个 class 回复,如下所示:

@Entity
public class Question implements Serializable {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  protected Long id;
  protected String texte;

  @OneToMany(mappedBy="question")
  private List<Reponse> reponses;


@Entity
public class Reponse implements Serializable {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  protected Long id;

  @ManyToOne
  @JoinColumn(name = "question_id")
  private Question question;

当我从数据库中调用类型问题时,这应该也会给我带来一个由 "question" 映射的响应列表。

但是我得到了一个 NULL 值并且这个堆栈在列表中 object :

Error = Exception occured : com.sun.jdi.InvocationException

有人知道它是什么吗?

您需要急切地获取回复:

@OneToMany(mappedBy="question", fetch = FetchType.EAGER)
private List<Reponse> reponses;