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

Equality test for entity bean

 
Stephen Selvaraj
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I jus took a mock test,
A client can determine whether two entity beans are same by comparing their primary key using equals method (true/false)
I responded true, but the correct ans was false.

any comments..
- Stephen
 
Sirajudeen Mohamed
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
It is true in case of isIdentical(EJBObject o)

Thanks
Siraj
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A client can determine whether two entity beans are same by comparing their primary key using equals method (true/false)


This is true. If the PKs are equal then the two entity beans are same.
 
Praveen Kumar Mathaley
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a primary key can be simple string, which may be same for two different beans, but it doesn't mean that the two entity beans are same,
it's just an possibility...
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a primary key can be simple string, which may be same for two different beans, but it doesn't mean that the two entity beans are same,
it's just an possibility...


If the Pk is same then that means the beans are same. Think about it , you have a database table and two records can't have the same primary key becuase pk is ment to be unique. That means if PK is same then the entity objects are same.
 
Praveen Kumar Mathaley
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear parihar,
what i meant was two different beans ( i.e two different tables ) can have same primary key.. hope this clears the issue...
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy !

The primary key class can be specific to a particular entity bean class.

That is, each entity bean can define its own primary key class. Or multiple entity beans CAN share the same primary key class.

If two entity objects with the SAME home interface have the SAME primary key, they are considered IDENTICAL entity objects. If they have a different primary key, they are considered different entity objects.

There are 2 ways of comparing Entity Beans:

1. Using isIdentical(EJBObject obj) method of javax.ejb.EJBObject interface on bean's REMOTE interface, or isIdentical(EJBLocalObject obj) method of javax.ejb.EJBLocalObject interface on bean's LOCAL
interface.



2. Comparing primary keys of two entity object references (ONLY FROM THE SAME HOME INTERFACE !) :



More details here :
http://java.boot.by/bcd-guide/ch08s02.html

regards,
MZ
 
Thomas Vezhambacheril
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Stephan,

You can conclude the answer is true only if

A client can determine whether two entity beans are same by comparing their primary key using equals method if the entity beans are from same Home

Am I correct ?

means if they includeed the clause "and the entity beans are from same Home " the answer was true.

Best Regards
Thomas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic