Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Common EJBObject and SessionBean interface  RSS feed

 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't getting any answers in the Bunkhouse Porch, so here's a link:
Bunkhouse Porch common interface question
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Interface can define to throw the RemoteException (in fact, any necessary exceptions), but the real class method does not necessary to throw such exception.

Nick
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Question
Why the real class method does not necessary to throw such exception ?

My Answer
Because EJB Container is throws exception after have some error occur.

..... please comment .....
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why the real class method does not necessary to throw such exception ?


Because Java language specification allows method implementations to throw less checked exceptions than the inteface method has declared.

Eg,




[ July 21, 2004: Message edited by: Alex Sharkoff ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why the real class method does not necessary to throw such exception

It is becos the real EJB class dont know what exceptions to be thrown, when there are some unexpected exception occurs.

For example, when there are not enough system resources, a system exception will be thrown. However, how come the EJB itself knows where is the client? Remote? (to throw RemoteException) or Local? (to throw EJBException).

Thus, the exception that really throw out is determined by the container, instead of the EJB object itself.

Nick
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all comment.

It's clear....
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, since the bean class is same for both remote and local clients it does not make sense to throw RemoteException from the bean class.
 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Cheung:
The Interface can define to throw the RemoteException (in fact, any necessary exceptions), but the real class method does not necessary to throw such exception.

Nick


Correct, although I hate declaring something like that if I'm not going to throw it. Code should be self documenting, and the throws signature implies that it does something it doesn't.
 
Victor Larr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick,
I posted this reply to your other post

You have to define 2 interfaces A and B, B extends A and have the same methods but without RemoteException. Parent interface A will declare RemoteException and your remote interface can extend it. Your bean will implement B which does not throw RemoteException. Child can specialize or not declare exceptions when overwriting operations from parent.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!