aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Mock question - Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Mock question -" Watch "Mock question -" New topic
Author

Mock question -

mini mehta
Ranch Hand

Joined: Oct 22, 2000
Posts: 120
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

Joined: Oct 22, 2000
Posts: 120
I am looking for answers guys!!!
Vipin Mohan
Ranch Hand

Joined: Nov 15, 2003
Posts: 79
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

Joined: Aug 26, 2001
Posts: 7610
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 ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mock question -