Every entity bean home interface has a mandatory findByPrimaryKey() method. The EJB specification has always allowed you to specify custom finder methods in the home interface for more specific and different lookups.

Since EJB 2.0, the specification added a standard EJB query language (EJ-BQL). Using EJBQL to replace the implementation of a finder method does not in any way affect the source of an entity bean. To add finder methods to a CMP entity bean, you need to use EJ-BQL.

For this tip, we create some customer finder in CMP EJB.

A home interface with finder:

 public interface PersonBeanHome extends EJBHome {
    public PersonBean create(PersonKey holding)
      throws CreateException, RemoteException;
    public PersonBean findByPrimaryKey(PersonKey primaryKey)
      throws FinderException, RemoteException;
    // our own finder method, searching persond by the first name:
    public Collection findByFirstName(String firstName)
      throws FinderException, RemoteException;

Deployment descriptor with EJB-QL statement:

		<!-- main bean definitions -->
			<!-- declaration of a primary key class  -->

				<!-- a statement selecting all the persons 
                                     with the name specified: -->
   <![CDATA[SELECT OBJECT(p) FROM PersonBean AS p WHERE a.firstName == ?1]]>