Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Implementing the Home Interfaces

The home interfaces (remote and local) are used to create the session bean instance; thus, they define the create method for your bean. As Table 11-3 shows, the type of create methods you define depends on the type of session bean you are creating:

Table 11-3 Home Interface Create Methods

Session Bean Type Create Methods

Stateless Session Bean

Single create method only, with no parameters.

Stateful Session Bean

One or more create methods with whatever parameters define the bean's state.


For each create method, you define a corresponding ejbCreate method in the bean implementation.

Implementing the Remote Home Interface

A remote client invokes the EJB through its remote interface. The client invokes the create method that is declared within the remote home interface. The container passes the client call to the ejbCreate method–with the appropriate parameter signature–within the bean implementation. The requirements for developing the remote home interface include:

  • The remote home interface must extend the javax.ejb.EJBHome interface.

  • All create methods may throw the following exceptions:

    • javax.ejb.CreateException

    • javax.ejb.RemoteException

    • optional application exceptions

  • All create methods should not throw the following exceptions:

    • javax.ejb.EJBException

    • java.lang.RunTimeException

Example 11-5 shows a remote home interface called HelloHome for a stateless session bean.

Example 11-5 Remote Home Interface for a Stateless Session Bean

package hello;

import javax.ejb.*;
import java.rmi.*;

public interface HelloHome extends EJBHome {
  public Hello create() throws CreateException, RemoteException;
}

Example 11-6 shows a remote home interface called HelloHome for a stateful session bean. You use the arguments passed into the various create methods to initialize the session bean's state.

Example 11-6 Remote Home Interface for a Stateful Session Bean

package hello;

import javax.ejb.*;
import java.rmi.*;

public interface HelloHome extends EJBHome {
  public Hello create() throws CreateException, RemoteException;
  public Hello create(String message) throws CreateException, RemoteException;
  public Hello create(Collection messages) throws CreateException, RemoteException;
}

Implementing the Local Home Interface

An EJB can be called locally from a client that exists in the same container. Thus, a collocated bean, JSP, or servlet invokes the create method that is declared within the local home interface. The container passes the client call to the ejbCreate method–with the appropriate parameter signature–within the bean implementation. The requirements for developing the local home interface include the following:

  • The local home interface must extend the javax.ejb.EJBLocalHome interface.

  • All create methods may throw the following exceptions:

    • javax.ejb.CreateException

    • javax.ejb.RemoteException

    • optional application exceptions

  • All create methods should not throw the following exceptions:

    • javax.ejb.EJBException

    • java.lang.RunTimeException

Example 11-7 shows a local home interface called HelloLocalHome for a stateless session bean.

Example 11-7 Local Home Interface for a Stateless Session Bean

package hello;

import javax.ejb.*;

public interface HelloLocalHome extends EJBLocalHome {
 public HelloLocal create() throws CreateException;
}

Example 11-8 shows a local home interface called HelloLocalHome for a stateful session bean. You use the arguments passed into the various create methods to initialize the session bean's state.

Example 11-8 Local Home Interface for a Stateful Session Bean

package hello;

import javax.ejb.*;

public interface HelloLocalHome extends EJBLocalHome {
  public HelloLocal create() throws CreateException;
  public HelloLocal create(String message) throws CreateException;
  public HelloLocal create(Collection messages) throws CreateException;
}