Can any buddy tell me why ejbFinder method return empty collection if there is no records in database as per the condition specify in EQL. While finder method who is returning the entity bean instance throws FinderException to indicate that there is such record in database.
Finder methods are based on findByPrimaryKey() notion. If you have a valid key for a record, then the record must exist somewhere (since the key/record were created together).
Try to follow this logic... if you didn't use keys for finder() method, then you could return multiple records which would be a problem since the return type must be a single object, therefore, all searches must be such that *at most one record* should be returned. And with that, all searches must therefore use a key for the record. But, the record must exist before the key, so any key you have should reflect a valid record, else you could possibly return multiple records. Therefore, all finder() methods should return *exactly one record* and throw exceptions if they do not.
Finally, ejbFinder() methods are really for when you are not sure if the data you have is a key or not, therefore it may return 0, 1, or a hundred records. [ November 29, 2005: Message edited by: Scott Selikoff ]
Basically, use "single result finders" are used when there should be one and only one to match the criteria. If none match the criteria, a FinderException will be thrown - this is your basic findByPrimaryKey.
But a FinderException will also be thrown if more than one entry match the criteria. If you make a finder called findByName, and there are two entries in the database with the same name (which is possible if Name is not the primary key), a FinderException will be thrown. [ November 29, 2005: Message edited by: �dne Brunborg ]
Entia non sunt multiplicanda praeter necessitatem
Joined: Sep 22, 2005
Hi Scott, I m not satisfied with ur KEY explanitation..... as far as findByPrimaryKey() is concerned u r right.
Take this example of finder method in which i m not giving any KEY value in my finder method :
Method take student name as argument so this method throw FinderException in following conditions : 1. When there is no record found in data base. 2. When there is more than one record found in database.
So when one finder method which is returning instance the entity bean throw finder exception to indicate that there is something goes wrong .
Then why can't one finder method which return the collection/set throw finder exception so indicate that there is something goes wrong or no record found as per the EQL.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com