Java Reference
In-Depth Information
import java.rmi.*;
import java.util.*;
import javax.ejb.*;
public interface MemberHome extends EJBHome {
public Member create(String id, String lastName, String firstName, int
membershipYear)
throws CreateException, RemoteException;
public Member findByPrimaryKey(String id)
throws FinderException, RemoteException;
public Collection findByMembershipYear(int minYear)
throws FinderException, RemoteException;
}
The home interface may define one or more create methods. The overloaded create methods must
have different signatures. The home interface create methods all return the EJB's remote interface,
which in the preceding example is Member , and they all throw CreationException and
RemoteException . The bean developer may define a create method to throw additional application-
specific exceptions to address their specific requirement in exception handling.
Note that the MemberHome interface extends the EJBHome interface, which is listed in Listing 21-3 . The
EJBHome interface defines two remove methods. The first method removes an EJB object identified by
a handle. A handle is an object that provides a reference to an EJB object and can be stored in
persistent storage. The second method removes an EJB object identified by its primary key.
Listing 21-3: EJBHome interface
Import java.rmi.RemoteExceptions;
Public interface EJBHome extends java.rmi.Remote {
Void remove(Handle handle) throws RemoteException,
RemoveException;
Void remove(Object primaryKey) throws RemoteException,
RemoveException;
EJBMetaDate getEJBMetaData() throws RemoteException;
HomeHandle getHomeHandle() throws RemoteException;
}
Like the session bean implementation discussed in the previous chapter , the BMP entity-bean
implementation class implements the create and remove methods defined in the home interface.
However, the corresponding methods for the create methods are named ejbCreate in the
implementation class, and they return a primary key object instead of the remote interface. The
corresponding methods for the remove methods are named ejbRemove in the implementation class,
and they do not take any argument. The differences in name and signature between the interface
methods and implementation class methods are due to the fact that the life cycle of an entity bean is
managed by the EJB container. It is critical to understand the EJB life cycles in order to master the use
of EJB.
Search WWH ::




Custom Search