I have the following table, currently I can update the User object to add or remove a role, but I cannot add a role to a new user when it is being created (User's roles are added on the same form on the UI) because the intermediate table User_Role is expecting a User Obj for his ID, so naturally on insert I get a User.User_ID = ?.
Is there any common way to solve this? I was thinking on perhaps trying to get the ID of the inserted user after Save and then calling my update function. I didn't want to to this because I am concerned about performance, specially in the future when bulk uploads may happen.
I am using CrudRepository on my userRepository.
if(userRequest.getUser().getIdUser() <= -1){
newUser.setIdUser(0);
newUser.setIsActiveUs(true);
newUser.setDateOfJoin(getCurrentDate());
nuser = usersRepository.save(newUser);
//Get created user and send it to update() with the roleList?
}