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

Mock question -

 
mini mehta
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code taken from some enterprise bean class (Assume all reference variables have been declared properly and the code has been compiled successfully):


EJBObject obj = ejbContext.getEJBObject();
Object pkey = obj.getPrimaryKey();

What type of bean may contain such code?
A. Message-driven bean
B. Stateless session bean
C. Stateful session bean
D. None of the above



I was first thinking this can only happen in entity bean. But then I realize that all other type of bean can actually get the reference component interface of an enity bean via a method argument. Well in that case all type of beans can contain such code. Or can they?
 
mini mehta
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for answers guys!!!
 
Vipin Mohan
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Mini

In the example, the EJB object reference is obtained from the EJBContext and not as a method argument. So naturally this code is from an entity bean.
Unless it is explicitly mentioned that the reference is passed as a method argument, you should assume that it is from an entity bean, since only they can have primary keys.

Thanks
Vipin
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the question statement as it is formulated, you cannot know for sure that this code snippet really comes from an entity bean. While it is true that primary keys only make sense in the context of entity beans, it is also possible to call getPrimaryKey() on an EJBObject of a session bean but a RemoteException would be thrown at runtime. Since the question statement only says that the code compiles successfully, there is no hint as to how it behaves at runtime, and thus, B and C would be the correct answers.
[ June 21, 2004: Message edited by: Valentin Crettaz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic