我有两个实体,当我想得到grade.getSubcompetence()
. 保存实体时发生错误,因为子能力数据为空。当我调试时,我看到错误:
“java.lang.StackOverflowError”异常。无法评估 _$$_jvstea5_f.toString()
年级实体:
@Entity
@Data
@NoArgsConstructor
@ToString(exclude = {"subcompetence"})
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "GRADE")
public class Grade {
@JsonBackReference
@ManyToOne(
fetch = FetchType.LAZY,
optional = false)
@JoinColumn(name = "SUBCOMPETENCE_ID", nullable = false)
private Subcompetence subcompetence;
@JsonBackReference
@ManyToOne(
fetch = FetchType.LAZY,
optional = false)
@JoinColumn(name = "LEVEL_ID", nullable = false)
private Level level;
}
子能力实体:
@Entity
@Data
@NoArgsConstructor
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "SUBCOMPETENCE")
public class Subcompetence {
@JsonManagedReference
@OneToMany(
mappedBy = "subcompetence",
fetch = FetchType.LAZY,
cascade = CascadeType.ALL)
private List<Grade> grades;
}