File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finder returning collection

 
Chetan Sahasrabudhe
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gemini Moses
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returns empty collection == collection.size() = 0
 
Chengwei Lee
Ranch Hand
Posts: 884
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic