How to do batch delete from the sql table in spring boot.
I have many to many relationship intermediate table. I want to remove few data based on the similar request payload.
{
user : “SomUser”,
transaction : [“A”,”B”]
}
Now here is my controller and here I am able to get the request payload from the request and I am getting input and passing to service.
@PostMapping(“/remove”)
public EntityModel<TrasnDTO> removeByUserId(
@RequestBody TrasnDTO input
) throws IOException {
TrasnDTO someVar = transeService. deleteTransByUser(input);
return null; // will write once it complete
}
Here is my Service Interface
TrasnDTO deleteTransByUser(TrasnDTO input);
Implementation :
@Override
public TrasnDTO deleteTransByUser(TrasnDTO input){
for(int counter=0; counter<input.getTrans().size(); counter++){
UUID transVal = input.getTrans().get(counter);
transRepository.removeUser(input.getUserId(), transVal);
}
return null;
}
In My TransRepo :
@Modifying
@Transactional
@Query("delete from trans_user where user_id = :user_id and trans_id = :trans_id)
void removeUser(UUID user_id, UUID trans_id);
My question is how should I write in impl method to go to repository and delete that. I am using Java 11.
I am getting error as I don't have specific repo for trans_user
Error : Cannot resolve method 'removeUser' in 'TransRepository