I have the following entity:
@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;
...
}
If I insert an object of that class into the table, everything works fine. However, when I add the following to the entity:
@Column(name = "owner", updatable = false, insertable = false)
private UUID ownerId;
I get the following error:
Cannot add or update a child row: a foreign key constraint fails (`organizer`.`calendar`, CONSTRAINT `FK3f7d9mholcykdaygm3bnwhwg7` FOREIGN KEY (`owner`) REFERENCES `user_info` (`id`))
Is it possible to have a reference to the foreign key in this scenario? If I omit the reference and just do owner.getId()
, will the OrganizerUser object be loaded?