Finder method question?


EJB programming & troubleshooting: Finder method question?

  1. Finder method question? (3 messages)

    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!
    thanks veterans!

    Threaded Messages (3)

  2. Finder method question?[ Go to top ]


    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
    page 263-264. FinderException
    From the client&#8217;s perspective, a FinderException (or a subclass of FinderException) indicates that an application level error occurred during the find(...) operation. Typically, the client&#8217;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. ObjectNotFoundException
    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.
  3. Finder method question?[ Go to top ]


    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?

  4. Finder method question?[ Go to top ]

    Weblogic had the same problem (fixed in service pack 2 I think)

    As to why the difference... ?? No idea.