In HFEJB p.560, a scenario is that A session bean calls getPrimaryKey() on its context and the bean gets an IllegalStateException. The context version of getPrimaryKey() is exposed only to entity beans but not to session beans. If you put sessionContext.getPrimaryKey() in source code, it will get compilor error. So how could we get IllegalStateException??? Please let me know if I am wrong. Thanks.
I've just checked the EJB API... I don't see any getPrimaryKey() in SessionContext interface... SO you cannot get IllegalStateException by using SessionContext... In addition, there are only two methods in javax.ejb.SessionContext; getEJBLocalObject() and getEJBObject(), while in javax.ejb.EntityContext; one more method(getPrimaryKey()) is added to obtain the primary key of the EJB object that is currently associated with this instance... Hope it helps...
Co-author of SCMAD Exam Guide, Author of JMADPlus SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
There is no getPrimaryKey() method in the SessionContext interface. However, there is a getEJBObject() and getEJBLocalObject() on which you can then invoke getPrimaryKey(). If a session bean does so, there won't be any compiler error since the compiler does not interpret the code, but the container will throw a RemoteException, respectively a EJBException at runtime.
My Linked In
posted 16 years ago
Thank you very much. I will correct my HFEJB. I hope Kathy and Bert should see this and correct this in the latest version of HFEJB.