Defining home interface methods

You can add methods to a home interface using the techniques described in Chapter 5, “Defining Component Interfaces.” However, the method signatures in a home interface must follow the design patterns described here to ensure that the generated code works as intended.

Patterns for create methods All beans can have create methods, which clients call to instantiate proxies for session beans and insert new data for entity beans. In Java, create methods must have names that begin with create, as in createAccount. (If defining an EJB 1.1 or 1.0 bean, create is the only valid name.)

Create methods must return the bean’s IDL remote interface type and raise CtsComponents::CreateException. Create methods can take any number of in parameters. To distinguish multiple overloaded create methods in IDL, append two underscores and a unique suffix. (This is the standard Java to IDL mapping for overloaded method names. When generating stubs for C++ and Java, EAServer removes the underscores and suffix from the stub method name). The pattern is as shown below:

remote-interface create
(
  in-parameters
) raises (CtsComponents::CreateException);

remote-interface create__overload-suffix
(
  in-parameters
) raises (CtsComponents::CreateException);

Patterns for finder methods Only entity beans can have finder methods. Clients call finder methods to look up entity instances for existing database rows. Names of finder methods typically have names beginning with find.

Every entity bean must have a findByPrimaryKey method that matches the following pattern:

remote-interface findByPrimaryKey
(
  in pk-type primaryKey
) raises (CtsComponents::FinderException)

where remote-interface is the IDL remote interface, and pk-type is the IDL type of the primary key.

Entity beans can have additional finder methods of two types:

Home interface business methods You can add business methods to the home interface for an entity bean to perform operations that are not specific to a single instance. For example, a home business method might return the average employee salary. For each home business method, the entity bean’s implementation class must have a method with the same name, except for the prefix ejbHome, and the same signature. For example, if the home interface declares:

public double averageSalary();

Then the implementation class must contain:

public double ejbHomeAverageSalary();

Home interface business methods cannot be used in EJB 1.1 or 1.0 beans.