Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 分离的实体未正确合并?_Java_Hibernate_Jpa - Fatal编程技术网

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;
    }
}