Noob question about hibernate criteria
- by Dimitri
Hello, I have a class called User which has 2 properties : login/password. I am trying to authenticate a user in my application using hibernate criteria but my request doesn't work.
[EDIT] The returned value is NULL. I have two users in my database for testing.
Here is my code :
@Override
public User authenticate(String login, String password)
throws NullPointerException {
Session session = this.getSession();
User user = (User) session
.createCriteria(User.class)
.add(
Restrictions.and(
Property.forName("login").eq(login),
Property.forName("password").eq(password)
)).uniqueResult();
if (user == null){
throw new NullPointerException("User not found");
}
return user;
}
Can someone tells me what is wrong with my code?
Happy new Year 2011 !!