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

getPrimaryKey() vs isIdentical()

 
Dean Oso
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to know under what circumstances its possible for 2 entity beans EJB object references to return different results for the getPrimaryKey() and isIdentical() tests?
For example, considering the following is it possible to have only 1 of the 2 System.out's being printed?
CustomerLocal cust1 = ...;
CustomerLocal cust2 = ...;
if ( cust1.getPrimaryKey().equals(cust2.getPrimaryKey()) {
System.out.println("pk eqs");
}
if ( cust1.isIdentical(cust2) ) {
System.out.println("isIdentical eqs");
}

I've looked in the spec and couldnt find what I thought was a definitive answer to this?
thanks,
Dean
 
shadow liu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As spec says: (P120)
---------
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.
------------
So, if the two reference is from same home, then these two method should
always return same result.
Else, like two different entity bean class, they can have same string as
their primary key, but they are not identical.
HTH.
Shadow.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic