Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

HFEJB - getPrimaryKey question

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic