Finder method exception

Discussions

EJB programming & troubleshooting: Finder method exception

  1. Finder method exception (1 messages)

    Hi Experts,
    I am using CMP 2.0.
    I have a finder method. When its not able to find anything database it throws exception. Is this normal behaviour or should it simply return null?

    I wonder why it should throw exception, when it can simply return null!

    Any ideas or advice is appreciated!

    Thanks
    Govinda
  2. Finder method exception[ Go to top ]

    Yes it is normal behavour as defined by the EJB spec to throw an ObjectNotFoundException. I suggest you read the spec on this area.

    As for why an exception? well the generally thinking is exceptions force developers to code for case where as checking return a null value can often be overlooked. For CMR finder methods that return collections or Sets, if there is no record then an empty Collection or Set is returned.

    David