我有以下实体:
@Entity
@Table(name = "calendar")
public class Calendar {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "name")
private String name;
@JsonIgnore
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "owner", referencedColumnName = "id")
private OrganizerUser owner;
...
}
如果我将该类的对象插入表中,一切正常。但是,当我向实体添加以下内容时:
@Column(name = "owner", updatable = false, insertable = false)
private UUID ownerId;
我收到以下错误:
Cannot add or update a child row: a foreign key constraint fails (`organizer`.`calendar`, CONSTRAINT `FK3f7d9mholcykdaygm3bnwhwg7` FOREIGN KEY (`owner`) REFERENCES `user_info` (`id`))
在这种情况下是否可以引用外键?如果我省略了引用并只执行owner.getId()
,是否会加载OrganizerUser对象?