No, this will not happen. you can consider them separate primary keys. Cheers Ashwani
----- Original Message ----- From: "Xie, Jinpeng" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, June 21, 2002 9:16 PM Subject: How does container passivate and activate Primary keys in Ent ity Bean? > The specification said 'it is possible that multiple entity beans use the > same primary key class' on section 9.8. > > Now I have two entity bean that uses the same primary key as indicated by > the following codes: > > -------------------------------------Primary Key > object--------------------------------------- > public class IDPrimaryKey { > private String id = null; > private Integer versionNumber = null; > > public void setID(String newID) { > this.id = newID; > } > > public String getID() { > return id; > } > > public boolean equals(Object obj) { > if (obj instanceof this) { > MyPrimaryKey temp = (MyPrimaryKey)obj; > return id.equals(temp.getID)); > } > > return false; > } > > > public int hashCode() { > return id.hashCode(); > } > > public Integer getVersionNumber() {return versionNumber;} > public void setVersionNumber(Integer newVersionNumber) > {this.versionNumber = newVersionNumber;} > } > > -------------------------------------------------Entity bean > 1----------------------------------------- > > public class Employee implements EntityBean { > private int versionNumberCount = 0; > private IDPrimaryKey primaryKey = null; > private EntityContext entityContext = null; > > > public void ejbActivate() throws > EJBException,java.rmi.RemoteException { > primaryKey = (IDPrimaryKey)entityContext.getPrimaryKey(); > } > > public void ejbLoad() throws EJBException,java.rmi.RemoteException { > > ... > ... load data from database......... > > primaryKey.setVersionNumber(new Integer(versionNumberCount++)); > } > ................ > > } > > -------------------------------------------------Entity Bean 2 > ------------------------------------- > public class Student implements EntityBean { > private IDPrimaryKey primaryKey = null; > private EntityContext entityContext = null; > > > public void ejbActivate() throws > EJBException,java.rmi.RemoteException { > primaryKey = (IDPrimaryKey)entityContext.getPrimaryKey(); > } > > ................ > public void ejbLoad() throws EJBException,java.rmi.RemoteException { > ... > ... load data from database.........don't set version number here > } > } > > -------------------------------------------------------------------------- -- > ------------------ > > If I am debuging them, two IDPrimaryKey objects in above two entity beans > have different memory > address although memeber attribute 'id' is the same among two IDPrimaryKey > objects and one in > Employee entity bean with non-null versionNumber and one in Student entity > bean with null versionNumber. > > What happens if the ejb container swap them out and bring them back sometime > later? > Can Employee entity bean get IDPrimaryKey object with non-null versionNumber > and Student entity bean get IDPriamryKey object with null versionNumber? > > > Jim > > =========================================================================== > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff EJB-INTEREST". For general help, send email to > [EMAIL PROTECTED] and include in the body of the message "help". > =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".