Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

SessionBean exceptions

 
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.
 
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?
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic