Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SessionBean exceptions

 
Peter Warde
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've notice that javax.ejb.SessionBean interface method signatures - ejbActivate, ejbPassivate, remove and setSessionContext - all throw EJBException and java.rmi.RemoteException - but that when writing the bean you don't need the implementation of these methods to throw these 2 exceptions.

I know it's legal for a implemented method of an interface to throw the same, subclass of or less exceptionsand I think the bean should never throw a Remote exception (because it is never remote, only the Remote Component and Remote Home interfaces are) but why does the interface have them if the bean doesn't need them or vice versa?

Thanks.
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Warde:

I know it's legal for a implemented method of an interface to throw the same, subclass of or less exceptionsand I think the bean should never throw a Remote exception (because it is never remote, only the Remote Component and Remote Home interfaces are) but why does the interface have them if the bean doesn't need them or vice versa?

Thanks.


Only the Remote Interfaces need to declare RemoteException exceptions and the reason is quite straight forward: the interfaces (home and component) expose the contract that the client uses to invoke methods on the bean or on the home object and are implemented by the stub to the EJBObject and EJBHomeObject. Because the Home and Component interfaces give life to remote objects (because these extend java.rmi.Remote), each method defined in those interfaces need to declare java.rmi.RemoteException, even if you are writing a simple RMI application. It is a bad mistake to declare RemoteException from within the bean class, because this would limit the bean visibility to remote clients; on the other side, if you declare local views for your bean, it's an error to declare RemoteException in the business methods.
[ September 03, 2004: Message edited by: Marco Tedone ]
 
Peter Warde
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation - I kind of knew this but it's good to have it reinforced. But why does SessionBean interface method signatures throw RemoteException as in "public void ejbActivate() throws RemoteException" if the implementation of these methods in the bean is never meant to throw a RemoteException? Is it just an oddity?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic