我有这个实体
@Entity
@Table(name = "REPORT_TASCK")
@Data
public class ReportTasck {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long id;
@Column(name = "type")
public String type;
@Column(name = "status")
public Integer status;
@Column(name = "type")
@OneToMany(mappedBy = "reportTasck", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public List<Bill> bills;
}
和
@Entity
@Table(name = "BIIL")
@Data
public class Bill {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long id;
@Column(name = "neme")
public String neme;
@Column(name = "status")
public Integer status;
@ManyToOne()
@JoinColumn(name = "REPORT_TASCK_ID")
public ReportTasck reportTasck;
}
然后我尝试填写并保存
ReportTasck reportTasck = new ReportTasck();
reportTasck.setStatus(0);
reportTasck.setType("standart");
List<Bill> bills = new ArrayList<>();
for (BillDto billDto : all) {//640 items
Bill bill = new Bill();
bill.setStatus(0);
bill.setNeme(billDto.getBill());
bill.setReportTasck(reportTasck);
bills.add(bill);
}
reportTasck.setBills(bills);
reportTasckRepository.save(reportTasck);
但是当开始这一行reportTasck.setBills(bills);
时,我在debbug模式下出错了方法扔了'java.lang.StackOverflowError' exception. Cannot evaluate entity.ReportTasck.toString()
当我尝试保存时,我收到此错误Method threw 'org.springframework.dao.DataIntegrityViolationException' exception.
could not execute statement; SQL [n/a]; constraint [null]
我不明白为什么我会收到此错误以及如何修复