Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

getPrimaryKey() vs isIdentical()

 
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
 
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.
    Bookmark Topic Watch Topic
  • New Topic