Hello everyone,
I need to get an User object from my database based on user and password Strings. I finally got it working this way:
Code:
public User getUser(String login, String password)
throws InfrastructureException {
Session session = HibernateUtil.getSession();
User user = null;
try { Criteria criteria = session.createCriteria(User.class);
criteria.add(Expression.eq("login", login));
criteria.add(Expression.eq("password", password));
user = (User) criteria.uniqueResult();
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
return user;
}
What i need to know is if this is the best way to do what i need. Is there any other better approach?
Thanks in advance