As a result of the invocation of a entity bean's finder method, if the entity bean cannot be found, what I should do? Throws FinderException or just return null, which one is better and more general!
I think all finders should throw a FinderException. FinderException has a subclass ObjectNotFoundException which indicates in a single object finder that nothing was found. Multi Object Finders return an empty collection if nothing is found (ie no exception is thrown).
Below is an extract from the ejb spec.
Enterprise JavaBeansTM Specification, Version 2.0
From the client’s perspective, a FinderException (or a subclass of FinderException) indicates that an application level error occurred during the find(...) operation. Typically, the client’s transaction has not been marked for rollback because of the FinderException. The Bean Provider throws the FinderException (or subclass of FinderException) from the ejbFind<METHOD>(...) method to indicate an application-level error in the finder method. The Bean Provider should not, typically, mark the transaction for rollback before throwing the FinderException. The Container treats the FinderException as any other application exception. See Section 18.3.
The ObjectNotFoundException is a subclass of FinderException. It is thrown by the ejbFind<METHOD>(...) method to indicate that the requested entity object does not exist. Only single-object finders (see Subsection 12.1.7) should throw this exception. Multi-object finders must not throw this exception. Multi-object finders should return an empty collection as an indication that no matching objects were found.
I've got a little addition for people using Oracle 9i AS. OC4J throws a NullPointerException when returning a null-value for a multiple-find-method. Therefor throwing a FinderException would be a better solution.
Does anybody know, what's the reason for making the spec not handling single- and multiple-find-methods equally?
Weblogic had the same problem (fixed in service pack 2 I think)
As to why the difference... ?? No idea.