我有以下映射在我的豆2NonUniqueObjectException:用同樣的標識值不同的對象已經與會議
父bean
@OneToMany(fetch = FetchType.LAZY, mappedBy = "application")
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
@JsonIgnore
private Set<ApplicationBuildVO> applicationBuilds = new HashSet<ApplicationBuildVO>(0);
子bean
相關@ManyToOne(fetch = FetchType.LAZY)
@Cascade({CascadeType.SAVE_UPDATE})
@JoinColumn(name = "APPLICATION_ID", nullable = false)
@JsonIgnore
private ApplicationVO application;
在我的服務方法 - 我執行查找應用程序bea ñ 創建一個子應用程序豆 - 其中有原始申請的參考
然後 - 當我嘗試在同一服務方法我收到以下錯誤,更新的父bean的值
Caused by: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.domain.dao.ApplicationVO#1]
at org.hibernate.engine.internal.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:617)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:301)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:244)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:109)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
我的服務代碼(精簡)如下
public boolean performBuild(Integer applicationId) {
ApplicationVO applicationVO = applicationServices.findAnyApplicationId(applicationId);
ApplicationBuildVO androidApplicationBuildVO = new ApplicationBuildVO();
androidApplicationBuildVO.setIsAndroid(true);
androidApplicationBuildVO.setIsSuccess(appBuildSuccessful);
androidApplicationBuildVO.setApplication(applicationVO);
androidApplicationBuildVO.setSoftwareVersion(androidSoftwareVersionVO);
androidApplicationBuildVO.setS3BucketName(mobileAppsBucketName);
androidApplicationBuildVO.setS3ArtifactKey(androidArtifact);
Integer applicationBuildId = applicationBuildServices.saveApplicationBuild(androidApplicationBuildVO);
applicationVO.setIsCurrentlyBeingBuilt(false);
boolean updateApplicationResult = applicationServices.updateApplication(applicationVO);
}
任何想法我可以做什麼來解決這個問題?
你能發佈你的更新代碼嗎? –
當然 - 只是更新了帖子 –
你的「@ Id」是如何分配的?我假設有某種'@ GeneratedValue' ... – Powerlord