我有两个实体,当我想获取grade.getSubcompetence()时。保存实体时发生错误,因为子权限数据为null。当我调试时,我看到错误:


  '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;
}

最佳答案

尝试在Subcompetence类中添加@EqualsAndHashCode(exclude="grades")

10-06 06:34