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

Mock question -

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking for answers guys!!!
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic