Try
if (null != result && result.size() != 0) {
}
Question
I have a function to check validity of a user as follows :
public boolean authenticate(String username, String password) {
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
String hql = "FROM LoginC L where L.userName=:uname and L.password=:pwd";
Query query = session.createQuery(hql);
query.setParameter("uname", username).setParameter("pwd", password);
//I am not sure how to proceed/check here?
List<LoginC> result = null;
result = query.list();
if (null != result) {
validUser = true;
} else {
validUser = false;
}
} catch (HibernateException he) {
System.out.println("error authenticating "+username+" "+he.getMessage());
} finally {
if (session != null) {
session.close();
}
}
return validUser;
}
I am not so expert on HQL and hence don't know what the query will return and how can I test it. Even on entering username-password, not existing in DB it returns true
. I am even not sure if hql query is correct.
Kindly help.
Solution
Try
if (null != result && result.size() != 0) {
}