The primary key will be one or more variables that map to the data.
The home interface has a single method named
|Lesson 3||Finding an entity bean using its primary key|
|Objective||Write the code to find an entity bean using its primary key.|
public Customer findByPrimaryKey (String primaryKey) throws FinderException, RemoteException
findByPrimaryKey()must be RMI IIOP compatible. In essence, this means that they must implement
int hashCode()methods, and have a single no-arg constructor. All the variables in the class must be public. You will find that all the Java-based data types are RMI IIOP compliant.
findByPrimaryKey()returns the remote interface to the EJBObject of the instance. It must be public and throw Finder and Remote exceptions. As you will see later, for bean-managed persistence,
findByPrimaryKey()maps to the
ejbFindByPrimaryKey()method in the bean. This structure is similar to session beans.
findByPrimaryKey()of the home interface to find a particular entity.
Customer bean1 = home.findByPrimaryKey("333");
java.lang.Stringand the return is the remote reference.