@OneToOne declares an entity-valued property as a one-to-one association. Configure optionality, cascading, fetching, and the database strategy on the association. section 9.1.1
Choose the association strategy according to lifecycle and optionality:
- Use a shared primary key when one entity is always stored first and can provide the other entity's identifier. section 9.1.1
- Use a foreign key association in other cases. section 9.1.4
- Use an intermediate join table when the one-to-one association is optional. section 9.1.4
Shared primary key: User and Address
Map User.shippingAddress with @OneToOne(fetch = FetchType.LAZY, optional = false, cascade = CascadeType.ALL) and @PrimaryKeyJoinColumn. Persist Address first, copy address.getId() into User, then save User inside a transaction. section 9.1.1
