File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB - getPrimaryKey question

 
Simon Ingram
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings fellow ranchers!

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?

best regards
Simon
 
james edwin
Ranch Hand
Posts: 393
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,

James
 
Simon Ingram
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Simon Ingram
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Roger,

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.

Should I put a note to this effect in the Errata?

regards
Simon
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic