These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: List not returning null but has size 0
PostPosted: Thu Nov 27, 2008 4:16 am 
Beginner
Beginner

Joined: Tue Mar 13, 2007 9:46 am
Posts: 20
I thought that the list() function used on a query should return null if no records was found. We have som cases where it does not return null, but the list.size() returns 0. This means that we have to check both for null and size=0 after queries. Is this correct?

String myQuery = "from myTable mtable where colA = :queryParam";

List myList = (List) session.createQuery(myQuery)
.setParameter("queryParam", "hibernate"
.list();

if (myList == null || myList.size() == 0) {
Log.debug(lctx, "Exit - no result", DebugLevel.FINE);
return; // RETURN ERROR
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2008 5:41 pm 
Newbie

Joined: Thu Aug 11, 2005 12:15 am
Posts: 9
The doc is pretty clear ... a list is returned ... check for size() to determine if there are results, not for null.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 1:39 am 
Beginner
Beginner

Joined: Tue Mar 13, 2007 9:46 am
Posts: 20
Sure about this? In most of our cases null is returned.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.