• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SessionBean exceptions

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic