java - How to verify criteria.list is empty? -


i've created criteria retrieve list of items. although expected, no result returned if condition 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 neither works

1) if(names.isempty())        system.err.println("cre empty");   2) if(names != null)        system.err.println("cre empty");  

you can use size() of list. if list's size 0, empty.

if(names.size() == 0){ //it empty }  if(names.size() > 0){ //it **not** empty } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -