On page 560 of Kathy and Berts justly famous book, the first bean scenario informs us that we will get an IllegalStateException if a our session bean calls getPrimaryKey() on its context.
Now the SessionContext interface does not contain getPrimaryKey. It is only accessible from the EntityContext interface, so should we not be treated to a compiler error rather than an IllegalStateException?
As we are not implementing "Sessioncontext" or EntityContext directly in bean code.It's implemtation is upto to the container and not to bean provider.That's why we will get not compile time exception.
My point is that if I call context.BigBananas() should I expect an IllegalStateException? Surely you can only call methods on a context that actually exist, like getEJBHome(). If you call getEEEHome() I would not expect the bean to compile. Can anyone confirm this?
What is meant by "on its context"? There are at least three explanations.
1. The term "on its context" should be replaced by "on its EJB object". In this case, any attempt by a session bean to call getPrimaryKey() on its EJB object will result in java.rmi.RemoteException being thrown.
2. The term "on its context" should be replaced by "via its context". As you can get the EJB object via the context, then getPrimaryKey() can be called. The result will be the same, java.rmi.RemoteException will be thrown.
3. The term "on its context" remains, in which case it is a compilation error.
you have confirmed what I thought. If a session bean calls getPrimaryKey() on its context (not on its EJBObject) there will be a compile error. So there is an error in Head First EJB on page 560. The first bean scenario, which states that the session bean will issue an IllegalStateException.