已传递的分离实体与具有复合PK

时间:2015-10-05 22:38:06

标签: hibernate java-ee jpa

错误: detached entity passed to persist: model.RoleClass

我正在尝试保留WorkflowInstance以及WorkflowPlayers列表,其中WorkflowPlayer实体具有复合主键

public class WorkflowInstancePlayerId implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@ManyToOne
@JoinColumn(name = "workflow_instance_id", referencedColumnName = "workflow_instance_id")
private WorkflowInstance workflowInstance;

@Id
@ManyToOne
@Cascade({CascadeType.MERGE})
@JoinColumn(name = "role_class_id", referencedColumnName = "role_class_id")
private RoleClass roleClass;

及其实体

@Entity
@IdClass(WorkflowInstancePlayerId.class)
public class WorkflowInstancePlayer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    private WorkflowInstance workflowInstance;
    @Id
    private RoleClass roleClass;

    @ManyToOne
    @JoinColumn(name = "badge", referencedColumnName = "badge")
    private Employee playerUser;
     ... other properties

最初根据查询确定RoleClassWorkflowPlayers列表,以确定工作流类型所需的角色,并使用faces页面的jsf Prerender进行设置,如下所示:

private void setupInstancePlayers() {
    ArrayList<WorkflowInstancePlayer> temp = new ArrayList<WorkflowInstancePlayer>();
    for (WorkflowClassRole wcr : wfc.getRole_list()) {
        WorkflowInstancePlayer wfiPlayer = new WorkflowInstancePlayer();
        wfiPlayer.setRoleClass(wcr.getRoleClass());
        wfiPlayer.setRole_required(wcr.getRole_required());
        temp.add(wfiPlayer);
    }
    wfi.setPlayer_list(temp);
}

并且在播放器列表上迭代地动态生成表单。此工作流类调用了Originator,Checker和Approver Roles。 (角色类已经保留) enter image description here

在表单提交时,我说错误detached entity passed to persist: model.RoleClass

我不想仅将角色类和工作流实例ID

的id保留为新的角色类

我的工作流实例实体看起来像

WorkflowInstance实体

@Entity
public class WorkflowInstance implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "trx_seq", sequenceName = "trx_seq", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "trx_seq")
    private Long workflow_instance_id;

    private String product_instance_id;

    @OneToMany(mappedBy = "workflowInstance")
    @OrderBy("step_num ASC")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<WorkflowInstanceWorkItem> work_item_list;

    @OneToMany(mappedBy = "workflowInstance")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<WorkflowInstanceWorkItemAction> work_action_list;

    @OneToMany(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "workflow_instance_id", referencedColumnName = "workflow_instance_id")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<WorkflowInstancePlayer> player_list;

    @ManyToOne
    @JoinColumn(name = "workflow_class_id", referencedColumnName = "workflow_class_id")
    private WorkflowClass workflowClass;
    ... other properties but probably not relevant

我尝试了各种级联选项jpa和hibernate。

0 个答案:

没有答案