Java Reference
In-Depth Information
There is nothing special about this interface. Note once again that every method throws
RemoteException . There is really no difference between the session bean and entity bean
remote interface. Moving on to the home interface, you will begin to see some of the major
differences.
Home Interface
The home interface still provides access to methods that control the EJB's lifecycle. There are
also some added implications because the entity bean is associated with persistence.
Two types of methods can exist in an entity bean's home interface—creation methods and
finder methods. You have seen create() methods in the session bean's home interface, where
you were required to have at least one such method. The process of creation returns to the
client a remote interface associated with a bean that has been initialized depending on the para-
meters passed to the create() method. Also, during this process, a new entry is added to the
database. When the client receives the remote interface, the bean has already been inserted into
the database. Creation methods are not required for an entity bean, allowing for information in
your database that is read only.
The second type of method in the entity bean's home interface is the finder method. These
methods allow the client to look for information in the database. These methods also return
remote interfaces for the specific bean type, however the beans are initialized from information
from the database. There were no finder methods present in the session bean. This makes sense
considering that there is nothing to look up when dealing with session beans.
Finder methods all have unique names that are structured find< method > . For example
findByName() . This will be one of the finder methods for your Quote Bean so that it is possi-
ble to look up all of the quotes with the same customer name. The parameters passed to the
finder method are usually used to build the search criteria.
Every finder method must either return the remote interface for the bean, or a collection of
these remote interfaces. This is determined while the bean is being designed, and depends on
whether the associated search always returns a unique result, or can return multiple entries.
Every entity bean is required to include a findByPrimaryKey() method in their home inter-
face. This is a single-object finder that takes the bean's primary key class as a search parame-
ter. We will talk a little more about the primary key class in the next section. Listing 12.6
contains the source for the QuoteHome interface.
L ISTING 12.6
QuoteHome.java
import java.util.Collection;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
Search WWH ::




Custom Search