我有这两个 Openjpa 实体:
@Entity
@Table(name = "os_wfentry")
public class JPAWorkflowEntry implements WorkflowEntry, Serializable {
private static final long serialVersionUID = -755511983025049452L;
@Id
private long id;
@Column(name = "name")
private String workflowName;
@Column(name = "state")
private Integer workflowState;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "workflowEntry")
private final List<JPACurrentStep> currentSteps;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "workflowEntry")
private final List<JPAHistoryStep> historySteps;
... 和这个:
@Entity
@Table(name = "os_currentstep")
public class JPACurrentStep implements Serializable, Step {
private static final long serialVersionUID = -3662582760248954945L;
@Id
private Long id;
@Column(name = "action_Id")
protected Integer actionId;
@Column(name = "step_Id")
protected Integer stepId;
protected String caller;
@Column(name = "finish_Date")
@Temporal(TemporalType.TIMESTAMP)
protected Date finishDate;
@Column(name = "start_Date")
@Temporal(TemporalType.TIMESTAMP)
protected Date startDate;
@Column(name = "due_Date")
@Temporal(TemporalType.TIMESTAMP)
protected Date dueDate;
@Column
protected String owner;
protected String status;
@ManyToOne
protected JPAWorkflowEntry workflowEntry;
当我运行我的应用程序时,我遇到了这个 SQL 错误:
ERROR: there is no unique constraint matching given keys for referenced table "os_wfentry" {stmnt 989537113 ALTER TABLE os_currentstep ADD FOREIGN KEY (workflowentry_id) REFERENCES os_wfentry (id) DEFERRABLE} [code=0, state=42830]
在我看来没关系,实际上表格是由唯一的 id “链接”的,我不明白为什么它会给我这个错误。