public User getByUsername(String username) {
Criteria criteria = getSession().createCriteria(User.class);
criteria.add(Restrictions.eq("username", username));
criteria.createCriteria("roles");
criteria.setMaxResults(1);
User user = null;
if (!criteria.list().isEmpty()) {
user = (User) criteria.list().get(0);
} else {
user = new User().invalidate();
}
return user;
}