尝试在大对象图上调用entityManager.persist()时出错。这就是我所拥有的。我试图坚持RecordType,它具有以下定义:
@OneToMany(mappedBy="recordType", cascade={CascadeType.PERSIST})
public Set<Form> getForms() {
return this.forms;
}
public void setForms(Set<Form> forms) {
this.forms = forms;
}
@ManyToOne(cascade={CascadeType.PERSIST})
@JoinColumn(name="workflow_id")
public Workflow getWorkflow() {
return workflow;
}
工作流程具有以下定义:
@OneToMany(fetch=FetchType.LAZY, mappedBy="workflow", cascade={CascadeType.PERSIST})
public Set<WorkflowState> getWorkflowStates() {
return this.workflowStates;
}
WorkflowState具有以下定义:
@ManyToMany(fetch=FetchType.LAZY, mappedBy="states", cascade={CascadeType.PERSIST})
public Set<Form> getForms() {
return this.forms;
}
表单具有以下定义:
@ManyToOne(cascade={CascadeType.PERSIST})
@JoinColumn(name="record_type_id", nullable=false)
public RecordType getRecordType() {
return this.recordType;
}
这引用了我想要保留的相同RecordType。 hibernate正在做什么:
DEBUG org.hibernate.SQL - insert into workflow
DEBUG org.hibernate.SQL - insert into workflow_state
DEBUG org.hibernate.SQL - insert into form
当它插入表单时,它传递一个空的record_type_id。所以我得到了:
MySQLIntegrityConstraintViolationException: Column 'record_type_id' cannot be null
不知怎的,当RecordType还没有被持久化时,hibernate试图保持Form,更糟糕的是,当它显然需要它继续时,它甚至不会试图在此阶段保持RecordType。我该如何解决这个问题?