File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes getPrimaryKey() vs isIdentical() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "getPrimaryKey() vs isIdentical()" Watch "getPrimaryKey() vs isIdentical()" New topic
Author

getPrimaryKey() vs isIdentical()

Dean Oso
Greenhorn

Joined: Jul 13, 2003
Posts: 9
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

Joined: Mar 19, 2001
Posts: 33
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.
 
IntelliJ Java IDE
 
subject: getPrimaryKey() vs isIdentical()
 
Threads others viewed
Counting identical items in DB
Algorithms: Sorting data on basis of three columns
Unable to put in one of the elements from another arraylist into another class(Resolved)
OPEN JPA - OneToMany uniderictional with multiple columns
Sessions... confused
MyEclipse, The Clear Choice