try {
userId=(Long)q.getSingleResult();
} catch (NoResultException e) {
throw new UserNotFoundException("User with this email has not been found");
}
User user = entityManager.find(User.class, userId);
String randomPass = RandomStringUtils.randomAlphanumeric(new Random().nextInt(8) + 6);
String encodedPass = encoderService.encodeString(randomPass);
user.setPassword(encodedPass);
if (sendEmailNotification) {
mailService.sentPasswordReset(email, randomPass);
}
}