Noob question about hibernate criteria
Posted
by
Dimitri
on Stack Overflow
See other posts from Stack Overflow
or by Dimitri
Published on 2011-01-02T19:25:04Z
Indexed on
2011/01/02
19:53 UTC
Read the original article
Hit count: 148
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 !!
© Stack Overflow or respective owner