我正在使用JPA进行数据库映射,并尝试在父(程序)和子实体(asset_condition)中进行插入。尝试插入数据库时,我不断收到ORA-01400:无法将NULL插入(“ ASSET_CONDITION”。“ PROGRAM_ID”)。
jpa如何在插入子记录期间自动获取此ID?我在映射中做错什么了?
@Entity
@Table(name="Program")
public class Program {
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
@JsonProperty("id")
private Long id;
@JsonProperty("assetConditions")
@OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
@JoinColumn(name="program_id", nullable=false)
private Set<AssetCondition> assetConditions = null;
}
这是子实体
@Entity
@Table(name="asset_condition")
public class AssetCondition implements Serializable {
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade=CascadeType.PERSIST)
@JoinColumn(nullable=false,name = "program_id", insertable = true)
private Program program;