I have an entity, PersonEntity, with an id (PERSON_ID column), a partition key (TENANT_ID column) and a collection of AddressEntity. The AddressEntity has an id (ADDRESS_ID), a partition key (TENANT_ID), and a field (VALUE).
This is the way it looks in the PersonEntity:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "person", orphanRemoval = true)
public Set<AddressEntity> getAddresses() {
return addresses;
}
Since CascadeType.ALL is set, when I a delete a person, it triggers a delete for the address as well. I use the Session's delete(Object)
method to delete the person.
The resulting SQL for that delete looks like this:
delete from address where address_id=?
delete from person where person_id=?
Is there any ORM way to perform this cascaded delete using both the person_id and tenant_id such that I get the following SQL generated:
delete from address where address_id=? and tenant_id=?
delete from person where person_id=? and tenant_id=?
I know I could simply write all the individual deletes using SQL, but I like the simplicity of using Hibernate to take care of all the associated table deletions.
The reason I want to do this is to ensure that the delete does not have to loop through partitions to find the address_id or person_id. If I gave it the tenant_id, it would be able to instantly go to the correct partition.