我在父实体(应用程序)上调用saveOrUpdate,其中父实体与子对象(审核应用程序)具有一对多的双向映射。 当在父对象上调用saveOrUpdate时,它将进入无限循环,并且堆栈上出现float null错误。 我想保持双向关系不变。
有人可以帮我知道我在做什么错。任何潜在客户都将在这个时候提供很大的帮助。 我在下面提供了完整的代码:
我尝试在关系的子方面使用JsonIgnore批注,但是没有运气。
子实体:auditapplication:
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MOTS_ID",referencedColumnName = "MOTS_ID",
nullable = false, insertable = false, updatable = false)
private Application application;
父实体:应用程序:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "application", cascade = CascadeType.ALL)
Set<AuditApplication> auditApplication;
永久代码:
Application app = applicationDao.getAppDetailsByMotsId(appOnboardingRequestDTO.getSelectedMotsId());
if(null != app){
app.setDirector(appOnboardingRequestDTO.getDirector());
app.setAvpTower(appOnboardingRequestDTO.getAvpTower());
app.setOnboarded(true);
if(null != app.getAuditApplication() && !app.getAuditApplication().isEmpty()){
//Check if module Id already exists
List<AuditApplication> existingAuditApps = AuditApplicationPredicate.filterAuditAppliations(app.getAuditApplication(),AuditApplicationPredicate.alreadyExists(appOnboardingRequestDTO.getModuleId()));
if(null == existingAuditApps || existingAuditApps.isEmpty()){
AuditApplication auditApp = new AuditApplication();
auditApp.setApplication(app);
auditApp.setModuleId(appOnboardingRequestDTO.getModuleId());
app.getAuditApplication().add(auditApp);
applicationDao.saveOrUpdate(app);
}else{
//Return error message that module already exists
return "Module Id already exists.";
}
}else{
Set<AuditApplication> auditApplicationSet = new HashSet<AuditApplication>();
AuditApplication auditApp = new AuditApplication();
auditApp.setApplication(app);
auditApp.setModuleId(appOnboardingRequestDTO.getModuleId());
auditApplicationSet.add(auditApp);
app.setAuditApplication(auditApplicationSet);
applicationDao.saveOrUpdate(app);
}
}
return "success";
}