• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Entity-Home interface-finder exception

 
vinod balaji
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt in Entity Bean Home Interface finder methods.
*Finder methods which returns a remote component i/f throws finder exception and
*Finder methods which returns a collection doesnt throw finder exception instead it will be empty.
*But in HFEJB pgno 275 it is given that even the finder methods with collection as return type throws finder exception.

Please Clear my doubt
 
Gaurav Chugh
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it goes like this

If the finder method single primary key it should throw javax.ejb.ObjectNotFoundException if the requested entity does not exist and javax.ejb.ObjectNotFoundException is subclass of FinderException


And if it finder method returns a collection of primary key then it should throw FinderException.

I hope it may clear your doubts.

Thanks
 
vinod balaji
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is clearly given that if the finder methods which return collection doesnt find anything it will return empty and not exception. so i think it should not throw finder exception.
But in book it throws finder exception
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
9.5.2 Finder Methods

The throws clause of every finder method on the remote home interface includes the java.rmi.RemoteException and the javax.ejb.FinderException

See also 10.5.6.2 Multi-object finders.
 
Steven Gao Song
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. It is because the Specifications say so.
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container throws the FinderException to indicate that something went wrong while finding requested entity object invoked by a client.

If an entity is not found, the client gets an ObjectNotFoundException in the case of a single-entity finder and an empty Collection (and no exception) in the case of a multiple-entity finder.

- single-entity finder=====>>>> javax.ejb.ObjectNotFoundException
- multiple-entity finder=====>>>> Empty Collection

FinderException is used to report a failure to find the requested EJB objects. Ans that's why we must need to add it in throws clause of finder method signature.

We must include this exception in the throws clause of all find methods that we declare in the entity bean's home interface and all the ejbFind (in the case of a BMP bean) and ejbSelect methods that we declare in the bean class.

i.e.

findXXX() of Entity Bean's Home interface
ejbFindXXX() of Entity Bean class
ejbSelectXXX() of Entity Bean class


Thanks,
Mahesh

-------
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic