This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Calling isIdentical on two entity beans

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
This is one of the mock exam questions. Please go through the code..

A session bean is executing the methods of two entity beans. While executing isIdentical() of two entity beans is showing that they are same even though they are not, then how can you determine that they are not identical?

1. compare their equals method in the Primary key class
2. compare their hashcode method in the Primary key class
3. find out the getPrimaryKey method from their respective entity bean class
4. find out from the getHandle method from their respective entity bean class
Select Two options:

What might be the correct answer to this question.
Thanks in Advance
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is good chance that the primary key classes of the beans are messed up. So I choose options 1 and 2. I'm counting on my container to return correct primary keys and handles. So I trust that the getPrimaryKey() and getHandle() methods work perfectly

I'm sincerely hoping that the real exam does not have these type of questions.
 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

This is what the specs have to say about this:

A client can test whether two entity object references refer to the same entity object by using the isIdentical
method. Alternatively, if a client obtains two entity object references from the same home,
it can determine if they refer to the same entity by comparing their primary keys using the equals
method


Further Enterprise JavaBeans architecture does not specify �object equality� (i.e. use of the ==
operator) for entity object references. The result of comparing two object references using the Java programming
language Object.equals(Object obj) method is unspecified. Performing the
Object.hashCode() method on two object references that represent the entity object is not guaranteed
to yield the same result.

As per me (1) and (3) are the correct answers so you retrieve the primary keys for the entity beans and compare the primary keys using equals method.

Thanks

Ravi
[ March 01, 2005: Message edited by: Ravindra Janapareddy ]
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic