我有一个应该编辑的票证对象。在我的票证对象中,有引用对象的属性(见下文)。...@ManyToOne(fetch = FetchType.EAGER)@JoinColumn(name = "project_id", referencedColumnName="id")private Project project;@ManyToOne(fetch = FetchType.EAGER)@JoinColumn(name = "costCenter_id", referencedColumnName="id")private CostCenter costCenter;...但是当我尝试更新实体时,我总是收到错误:无法提交 JPA 事务;嵌套异常是 javax.persistence.RollbackException:提交事务时出错@PutMapping("/tickets/{id}")@ResponseStatus(HttpStatus.OK)public Ticket updateTicket(@RequestBody Ticket ticket) throws Exception{ Optional<Ticket> o = this.ticketRepo.findById(ticket.getId()); o.ifPresent(element -> { if(ticket.getCostCenter() != null) { Optional<CostCenter> c = this.costCenterRepo.findById(ticket.getCostCenter().getId()); c.ifPresent( costCenter -> { element.setCostCenter(costCenter); }); } if(ticket.getProject() != null) { Optional<Project> p = this.projectRepo.findById(ticket.getProject().getId()); p.ifPresent(project -> { element.setProject(project); }); } this.ticketRepo.save(element); }); return o.orElseThrow(() -> new NotFoundException(ticket.getId()));}PS:当我触发更新而不进行更改时,一切正常。
1 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
你有一个StackOverflowError
强烈表明你在某处有一些无限递归(或者至少是一个非常深的递归):
Caused by: java.lang.RuntimeException: java.lang.StackOverflowError
在你很长的堆栈跟踪中重复出现的事实com.mycompany.test.config.AuditorAwareImpl.getCurrentAuditor
表明它以某种方式参与了你的无限递归,我敢打赌它来自这个类,以某种方式触发了首先可能触发它的任何东西org.springframework.data.auditing.AuditingHandler
。因此,请检查您的AuditorAwareImpl
代码和/或审核配置。
添加回答
举报
0/150
提交
取消