JPA级联合并不会持久化属性

时间:2013-10-14 11:45:12

标签: java persistence cascade openjpa

我在OpenJPA 2.0上有一个实体

@Entity
@Table(name = "os_wfentry")
@SequenceGenerator(name = "jwe_seq", sequenceName = "jwe_seq", initialValue = 10, allocationSize = 1)
public class JPAWorkflowEntry implements WorkflowEntry, Serializable {

    private static final long serialVersionUID = -755511983025049452L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "jwe_seq")
    private long id;

    @Column(name = "name")
    private String workflowName;

    @Column(name = "state")
    private Integer workflowState;

    @Column(name = "version")
    private Integer version;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "entry")
    private final List<JPACurrentStep> currentSteps;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "entry")
    private final List<JPAHistoryStep> historySteps;

    public JPAWorkflowEntry() {
        currentSteps = new ArrayList<>();
        historySteps = new ArrayList<>();
    }

... 在JPACurrent和JPAHistory步骤中我插入了:

@ManyToOne
    @Column(name = "entry_id")
    protected JPAWorkflowEntry entry;

这一切都是正确的(理论上);但是当我尝试保存(或更新)JPAWorkflowStore的新实例时,具有(当前或历史)步骤的NOT EMPTY列表,步骤列表属性不会在db上持久存在,并且它始终是空列表。你能帮助我吗??我做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要为JPACurrent和JPAHistory指定@JoinColumn(name =“id”,nullable = false)。

你做的是@Column(name =“entry_id”)我没有看到“entry_id”映射到JPAWorkflowEntry中的任何cölumn