@ManyToOne JPA 关系可以为空吗?
2022-09-01 16:42:53
我有一个表,具有另一个表的外键(多对一关系),但我希望它是可空的。
像这样:
public class SubType() {
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
}
public class TopUp {
@Column(nullable = true)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private SubType subType;
}
但抛出并说子类型不能为空。有没有办法让 ManyToOne 接受 null?@Column(nullable = true)
NullPointerException