Java 分离的实体未正确合并?
我需要一些帮助,我的代码如下Java 分离的实体未正确合并?,java,hibernate,jpa,Java,Hibernate,Jpa,我需要一些帮助,我的代码如下 @Override public SEDocumentListWidget clone() throws CloneNotSupportedException { final SEDocumentListWidget clone = (SEDocumentListWidget) super.clone(); final Set<SEDocumentListCategoryList> listCopy = new HashSet<&g
@Override
public SEDocumentListWidget clone() throws CloneNotSupportedException {
final SEDocumentListWidget clone = (SEDocumentListWidget) super.clone();
final Set<SEDocumentListCategoryList> listCopy = new HashSet<>(clone.getDocumentListCategoryList());
SEEntityManager.flush();
SEEntityManager.detach(listCopy);
for (SEDocumentListCategoryList listItem: listCopy) {
listItem.setOid(UUID.randomUUID().toString());
}
final Set<SEDocumentListCategoryList> listCopyMerged = SEEntityManager.getEntityManager().merge(listCopy);
clone.setDocumentListCategoryList(listCopyMerged);
return clone;
}
查看您的代码,我认为您希望复制持久化对象并使用新id持久化它们。在这种情况下,我认为您必须使用
persist()
,而不是merge()
(它尝试更新分离的实体) 查看您的代码,我认为您希望复制持久化对象并使用新id持久化它们。在这种情况下,我认为您必须使用persist()
,而不是merge()
(尝试更新分离的实体) 你能粘贴SEDocumentListCategoryList
实体吗?当然,我会用它编辑我的帖子:谢谢,你能添加EntityObject
?:)它有点大,它还有两个属性,OID是主键,NRVERSION是另一个。你可以粘贴SEDocumentListCategoryList
实体吗?当然可以,我会用它编辑我的帖子:谢谢,你也可以添加EntityObject
?:)它有点大,它还有两个属性,OID是主键,NRVERSION是另一个
final Set<SEDocumentListCategoryList> listCopyMerged = SEEntityManager.getEntityManager().merge(listCopy);
package com.softexpert.dashboard.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import com.softexpert.platform.annotation.Audit;
import com.softexpert.platform.artefacts.EntityObject;
/**
*
* @author elia.melfior
*
*/
@Entity
@Audit(dataChange = true, dataLoad = false)
@Table(name = "SEDOCUMENTLISTCATEGORYLIST")
public class SEDocumentListCategoryList extends EntityObject {
private static final long serialVersionUID = 1L;
private Integer cdCategory;
@Column(name = "CDCATEGORY")
public Integer getCdCategory() {
return this.cdCategory;
}
public void setCdCategory(Integer cdCategory) {
this.cdCategory = cdCategory;
}
}