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.
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.
------------------------------------------------------------------------------ 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. ------------------------------------------------------------------------------
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.
SCJP, SCWCD, SCBCD, OCA J8
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding: