This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes finder returning collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "finder returning collection" Watch "finder returning collection" New topic

finder returning collection

Chetan Sahasrabudhe
Ranch Hand

Joined: Aug 09, 2004
Posts: 75

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,


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

Joined: Jan 04, 2001
Posts: 245
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
Don't get me started about those stupid light bulbs.
subject: finder returning collection
Similar Threads
Encapsulation and "getting" null references
dynamic render?
FinderException for findBySomeCriteria(...)
findXXX methods in EJB 2.x
how to use finder methods with cmp?