8.2. The Home Interface

In addition to "home business methods," the Home interface is used by any client application to create, remove, and retrieve instances of the Entity Bean. The bean provider needs to provide only the desired interface; the container will automatically provide the implementation. If it is remote, the interface must extend the javax.ejb.EJBHome interface; if it is local, the interface must extend the javax.ejb.EJBLocalHome interface. The methods of a remote home interface must follow the rules for Java RMI. The signatures of the create and find... methods should match the signatures of the ejbCreate and ejbFind... methods that will be provided later in the Enterprise Bean implementation class (the same number and types of arguments, but different return types).

8.2.1. create Methods

8.2.2. remove Methods

8.2.3. finder Methods

Finder methods are used to search for an EJB object or a collection of EJB objects. The arguments of the method are used by the Entity Bean implementation to locate the requested entity objects. For bean-managed persistence, the bean provider is responsible for developing the corresponding ejbFinder methods in the bean implementation. For container-managed persistence, the bean provider does not write these methods; they are generated at deployment time by the platform tools; the description of the method is provided in the deployment descriptor, as defined in Section 8.7 Configuring Database Access for Container-Managed Persistence. In the Home interface, the finder methods must adhere to the following rules:

At least one of these methods is mandatory: findByPrimaryKey, which takes as argument a primary key value and returns the corresponding EJB object.

8.2.4. home Methods

Home methods are methods that the bean provider supplies for business logic that is not specific to an Entity Bean instance.

8.2.5. Home Interface Example

The Account Bean example, provided with the platform examples, is used to illustrate these concepts. The state of an Entity Bean instance is stored in a relational database, where the following table should exist, if CMP 1.1 is used:

create table ACCOUNT (ACCNO integer primary key, 
      CUSTOMER varchar(30),
      BALANCE number(15,4));

public interface AccountHome extends EJBHome {
    public Account create(int accno, String customer, double balance)
throws RemoteException, CreateException;

    public Account findByPrimaryKey(Integer pk)
throws RemoteException, FinderException;
    
    public Account findByNumber(int accno)
throws RemoteException, FinderException;

    public Enumeration findLargeAccounts(double val)
throws RemoteException, FinderException;

}