Since we bind a Contact entity to a Person, we can choose to give a name to the joining column. The name that we specify here will be the foreign key reference in the target entity, which is the contacts table:
@Table(name = "person")
@Entity
class Person : Identity() {
@Id
lateinit var identifier: UUID
lateinit var name: PersonName
lateinit var loginId: String
@Enumerated(EnumType.STRING)
var preferredLanguage: PreferredLanguage? = null
@OneToMany(cascade = arrayOf(CascadeType.ALL), fetch =
FetchType.LAZY)
@JoinColumn(name = "PERSON_ID")
lateinit var contact: List<ContactDetails>
lateinit var address: Address
}
As the ContactDetails entity always refers to the Person entity with the PERSON_ID as foreign key, we can mark it as non-nullable:
@JoinColumn(name = "PERSON_ID", nullable = false)
lateinit var contact: List<ContactDetails>