GeeCON Prague 2014*
The moose likes JDBC and the fly likes FinderException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "FinderException" Watch "FinderException" New topic
Author

FinderException

Nathan Huiras
Greenhorn

Joined: Jun 10, 2005
Posts: 3
I am using a Database Access Object class to retrieve data from a database. If I don't find an object in the database when trying to find it, should I use a FinderException, or an ObjectNotFoundException?
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
Nathan,

FinderException is a super class of ObjectNotFoundException(ONFE), So if you catch FinderException, ONFE will itself be caught. but infact both are used in different scenarios.

FinderException is the exception you need to catch as it better suits your requirement.

Cheers,
Rahul


Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
Nathan Huiras
Greenhorn

Joined: Jun 10, 2005
Posts: 3
When would it be better to use an ObjectNotFoundException versus a FinderException and why?
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
Nathan,

Hope this will help you.

FinderException- This exception indicates that an application error occurred (invalid arguments, etc.) while the container attempted to find the beans. Do not use this method to indicate that entities were not found. Multi-entity find methods return an empty collection if no entities were found; single-entity find methods throw an ObjectNotFoundException to indicate that no object was found.

ObjectNotFoundException - The ObjectNotFoundException is thrown from a single-entity find method to indicate that the container couldn't find the requested entity. This exception can be thrown by the container if the container is managing persistence, or it can be thrown explicitly by the bean developer in the ejbFind...() methods. This exception should not be thrown to indicate a business logic error (invalid arguments, etc.). Use the FinderException to indicate business logic errors in single-entity find methods. The ObjectNotFoundException is only thrown by single-entity find methods to indicate that the entity requested was not found. Find methods that return multiple entities should return an empty collection if nothing is found.

Cheers,
Rahul
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Moving to the JDBC forum. This forum is for Servlet questions only.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FinderException