• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception ?

 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Could you please explain the answer to this question -->

Question: What will happen when the given code snippet of HelloBean client is executed? Assume that HelloBean is a session bean, and the client is a local client.
...
7. HelloHome home = (MyHome) initContext.lookup("java:comp/env/ejb/myhome");
8. Hello hello = home.create(123);
9. home.remove(hello);
...

At line (9) what kind of exception will be thrown.

a) RemoveException
b) EJBException

I answered (b) since HomeInterface.remove(Object primaryKey) method expects a primary key and not a component interface to be passed as a parameter so IllegalArgumentException is thrown which is in turn wrapped as EJBException and re-thrown.

The actual answer is a).

Thanks

-- Ravi
 
Binoj Viswanathan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

As per ejb2.0 spec(p59 and p60 ) this shd thro RemoveException to the client(Local/remote).

binoj
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks Binoj!

The specs say:

6.3.2 Removing a Session Object
A remote client may remove a session object using the remove() method of the
javax.ejb.EJBObject interface, or the remove(Handle handle) method of the
javax.ejb.EJBHome interface.
Because session objects do not have primary keys that are accessible to clients, invoking the
javax.ejb.EJBHome.remove(Object primaryKey) method on a session results in a
javax.ejb.RemoveException.

RemoveException is the correct answer since hello (component interface extends Object) and thus it becomes a legal argument to the above method and hence the RemoveException.

Thanks

-- Ravi
 
Sanju Thomas
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi,

------------------------------------------------------------------------------
RemoveException is the correct answer since hello (component interface extends Object) and thus it becomes a legal argument to the above method and hence the RemoveException.
------------------------------------------------------------------------------

Can an iterface extends a class ???
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can an iterface extends a class ???


Of course not. But the basic rules of Java programming language allows you to pass an Object that implements some arbitrary interface as an argument to a method that accepts java.lang.Object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic