I am trying to delete from an many to many entity which is cascade.all but its not deleting ! i am confused ```@Transactional
public boolean deleteInputAndOutput(long id) {
// Get the current authenticated user
CustomUserDetails customUserDetails = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
User currentUser = customUserDetails.getUser();
// Retrieve the InputAndOutput entity by ID, or throw an exception if not found
InputAndOutput inputAndOutput = inputAndOutputRepository.findById(id)
.orElseThrow(() -> new NoInputAndOutputFound("This input or output is not present in the db " + id));
// Check if the authenticated user is associated with this InputAndOutput
if (inputAndOutput.getUsers().contains(currentUser)) {
// Remove the InputAndOutput from the user's inputAndOutputs list
currentUser.getInputAndOutputs().remove(inputAndOutput);
// Remove the user from the InputAndOutput's users list
inputAndOutput.getUsers().remove(currentUser);
// Save the updated user (removes the association)
userRepository.save(currentUser);
// Optionally, delete the InputAndOutput if no users are left
if (inputAndOutput.getUsers().isEmpty()) {
inputAndOutputRepository.delete(inputAndOutput);
}
return true;
} else {
// If the authenticated user is not associated with this InputAndOutput, return false
return false;
}
}```