Reputation: 7915
i have 2 entity Classes (AEntity for table A and BEntity for table B). Table A is linked to table B. So AEntity Class has a list of objects of BEntity and declared as shown below.
@OneToMany(mappedBy = "AEntity", cascade = CascadeType.REMOVE, fetch=FetchType.LAZY) private List items = new ArrayList();
If i remove the AEntity by using "entityManager.remove(aEntity)", this will also delete the BEntity for the B Table.
This is happening correctly for small number of data. But if the data is increased, it fails with exception "Out of operation records in transaction coordinator (increase MaxNoOfConcurrentOperations)".
This exception is happening because its deleting large number of data at one go. So i want to override the delete/remove operation of BEntity and want to handle deletion using pagination, that is if total of 1 lacks rows is to be deleted, i want to delete 1000 in one transaction then next 1000.
How can i achieve this. Please help
Upvotes: 0
Views: 164
Reputation: 77020
The solution is described with the pseudocode as follows (I do not use your technology, so I can only share the algorithm):
batchSize <- 1000
while A.listOfB.size() > batchSize do
tempList <- A.listOfB.copyBatch(batchSize)
tempList.deleteAll()
A.listOfB.deleteBatch(batchSize)
end while
A.delete()
I hope the algorithm is easy to understand.
Upvotes: 0