【发布时间】:2021-02-02 03:56:57
【问题描述】:
我正在使用单向 @ManyToOne 映射。代码如下所示。
public class PolicyCatalogEntity extends BaseEntity {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "policyReferenceId", referencedColumnName = "policyReferenceId",
nullable = false, insertable = false, updatable = false)
private PolicyConfigDetailsEntity policyConfigDetailsEntity;
@NotBlank
private String lobName;
}
PolicyDetailsEntity 看起来像这样
public class PolicyConfigDetailsEntity extends BaseEntity implements Serializable {
@NotNull
private Long policyReferenceId;
@NotBlank
private String policyName;
private boolean isActive;
}
我是否需要在PolicyCatalogEntity 中专门添加列policyReferenceId?
PS:policyReferenceId 不是主键。它只是一个复合键。
如果不是,那么我会收到以下错误
Field 'policy_reference_id' doesn't have a default value
Hibernate:
insert
into
policy_catalog
(created_at, created_by, last_modified_by, updated_at, version, end_date, is_active, lob_name, lob_ref_id_type, start_date, tnc_url)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
【问题讨论】:
-
如果没有,那么我会收到以下错误
Field 'policy_reference_id' doesn't have a default value
标签: java spring-boot hibernate spring-data-jpa hibernate-mapping