0

我有两个实体,当我想得到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;
}
4

2 回答 2

1

尝试@EqualsAndHashCode(exclude="grades")在您的 Subcompetence 课程中添加

于 2018-12-11T11:50:13.767 回答
0

添加添加@EqualsAndHashCode(callSuper=false)JsonIgnore如下所示

  @OneToMany(
            mappedBy = "subcompetence",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
@JsonIgnore
private List<Grade> grades;
于 2018-12-11T12:42:10.800 回答