Cascading

Since we have a one-to-many relationship here, this means that we can have one column in our contacts table that refers to a unique entry in the person table. Furthermore, we can specify how these entities can be bound. For example, we can perform cascading, as shown in the following code:

@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))
lateinit var contact: List<ContactDetails>

lateinit var address: Address
}

Cascading on the Person entity specifies that whenever we perform any operation on the Person entity, that operation passes down to all other entities that are bound to it. For example, if we save, update, or delete the Person entity, these operations are cascaded down to the ContactDetails entity.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset