Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB p.560 A session bean calls getPrimaryKey() on its context

 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic