JPA method to update roles for users
Well, you created a good code so far. Your lamda is OK. But there are some things about naming which could be improved


About the API setRolesByUserId, it is OK to accept userId as long. But about role, it could be better to change the Set to Set, and i think you're about to update for List of user, hence the name should change to updateUserWithRoleSet.
IMHO, It is totally OK to update one user at once => updateUserWithRole(long userId, Set&lt;Role&gt; roles&gt;