aspose file tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes finder returning collection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "finder returning collection" Watch "finder returning collection" New topic
Author

finder returning collection

Chetan Sahasrabudhe
Ranch Hand

Joined: Aug 09, 2004
Posts: 75
Hello,

HF book says that finder method returning single object will throw ObjectNotFoundException, but finders returning Collections will return empty collection for not finding any rows as per the criteria.

Returns empty collection == collection.size() = 0 OR
Returns empty collection == null

Client side validation should be,

OR


Thanks & Regards<br />Chetan
Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 244
Returns empty collection == collection.size() = 0
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
The beauty of returning an empty collection as opposed to returning null is that you do not need to incur the overheads of checking if your collection is null/non-null.

You can simply just iterate it as per usual. No checks on whether the size is 0 too (unless your situation warrants it).


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: finder returning collection
 
Similar Threads
FinderException for findBySomeCriteria(...)
how to use finder methods with cmp?
dynamic render?
findXXX methods in EJB 2.x
Encapsulation and "getting" null references