答案是:
@RequestMapping(value = "/game/play", method = RequestMethod.POST)
@ResponseBody
public User indexRequestPlay(@RequestParam String username, @RequestParam String password) {
User user = userRepository.findByUsernameAndPassword(username, password);
Random random = new Random();
int userscore = random.nextInt(5) + 1;
int npcscore = random.nextInt(5) + 1;
/////////////////////////////////////////////////////////////////////////////////
// aici adaug un camp in user.
user.getStartSessions().add(new Date());
/////////////////////////////////////////////////////////////////////////////////
Game game = new Game(userscore, npcscore, new Date());
game.setUser(user);
user.getGames().add(game);
userRepository.save(user);
return user;
}