O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required