【发布时间】:2020-05-22 15:35:21
【问题描述】:
我可能误解了 JPA 的一些基础知识。我得到了一种关于返回对象的循环引用......
我有一个问题列表,每个问题都有一个回答列表。 但是通过我所做的 JPA 映射,每个响应也有一个问题。 看这里:
@Entity
public class Question implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// A question has several responses
@OneToMany(mappedBy = "question", fetch = FetchType.EAGER)
private List<Reponse> reponses;
@Entity
public class Reponse implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
// This is here to specify the join column key "question_id"
@ManyToOne
@JoinColumn(name = "question_id")
private Question question;
正如您在此处看到的,我有一个问题[0],其中包含一个响应列表,但每个问题都有一个问题,其中还有一个响应列表等等...:
如何在不带整个对象及其所有子对象等的情况下指定连接列键?
非常感谢您的帮助!
乔斯
【问题讨论】:
标签: java jpa join persistence one-to-many