I have a table from which I'm calculating the current number of rows between two dates and using the resultant value in my 'to be inserted' rows in that same table.
I'm having issue when two concurrent requests come, say A1 and A2, and want to store new rows at the same time (after the calculation above), both have the same resultant, say 10 rows. Even though A1 should have 10, while A2 should get 11.
Both transactions are conflicting. So I need to lock the table. I know the lock function
aRepository.lock(Object);
but the issue is that this will lock only a row, and I want to lock the whole table(entity) as I'm calculating the total number of rows.