I have two entities like this with joins,
Entity Address:
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
@JsonBackReference
@EqaulsAndHashCode.Exclude
@ToString.Exclude
@JoinColumn(name="PERSON_ID", referencedColumns = "PERSON_ID")
private Person personDetails;
Entity Person:
@OneToMany(mappedBy = "personDetails", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@ToString.Exclude
@EqualsAndHashCode.Exclude
@JsonManagedReference
List<Address> addressList = new ArrayList<>();
I am deleting Address using AddressRespository.deleteAll(//list of address) inside a @Transactional method. This method then calls another method from a different service which is also annotated with @Transactional and updates one of the property of Person and performs the save operation.
As this stage it returns an error deleted instance passed to merge.
I tried to use flush after deleteAll which resolves this error but it did not delete anything in the database.
How can I achieve the desired outcome here?