Chapter 8. CMP: EJB QL

Find methods have been a part of the Enterprise JavaBeans specification since EJB 1.0. These methods are defined on the entity bean’s home interfaces and are used for locating entity beans. All home interfaces must have a findByPrimaryKey( ) method, which takes the primary key of the entity bean as an argument and returns a remote or local reference to that entity bean. For example, the Cruise EJB defines this find method in its home interface as:

public CruiseHomeLocal  extends  javax.ejb.EJBLocalHome {
  public Integer create(String name,ShipLocal ship) 
    throws CreateException;
    
  public CruiseLocal findByPrimaryKey(Integer key) 
    throws FinderException;
}

In addition to the mandatory findByPrimaryKey( ) method, home interfaces can define as many custom find methods as needed. For example, the Cruise EJB might define a method called findByName( ) for locating a Cruise with a specific name:

public CruiseHomeLocal extends javax.ejb.EJBLocalHome {
  public Integer create(String name,ShipLocal ship)
    throws CreateException;
    
  public CruiseLocal findByPrimaryKey(Integer key)
    throws FinderException;

  public CruiseLocal findByName(String cruiseName)
            throws FinderException;
}

It’s not obvious to the container how a custom find method should behave. In EJB 1.0 and 1.1, vendors came up with their own query languages and methods to specify the behavior of these other solutions. Consequently, the custom methods generally were not portable, and guesswork was required on the part ...

Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.