Reputation: 6620
I've created a criteria to retrieve list of items. Although as expected, no result will be returned the if condition does not work.
Criteria cre = session.createCriteria(Name.class,"name);
cre.add(Restrictions.eq("name.fname","Alex");
List<Name> names = (List<Name>) cre.list();
I used both following 'if' conditions but neither works
1) if(names.isEmpty())
System.err.println("cre is empty");
2) if(names != null)
System.err.println("cre is empty");
Upvotes: 1
Views: 1422
Reputation: 8113
You can use the size()
of the list. If the list's size is 0, it is empty.
if(names.size() == 0){
//it is empty
}
if(names.size() > 0){
//it is **not** empty
}
Upvotes: 1