Java Reference
In-Depth Information
On the other hand, with bean-managed persistence you must write the SQL statements and
logic to store the information to the database. However, you also have the ability to perform
complex joins, as well as use several statements if necessary to access your data.
Both methods of persistence have advantages and disadvantages and once again the one you
use is a decision you must make. For the purposes of this chapter you will develop a simple
bean implemented using container-managed persistence.
Entity Bean Interfaces and Classes
Let's jump right in and look at the necessary parts to develop an entity bean. The sample entity
bean you will develop is a Quote Bean. This container-managed bean will represent a cus-
tomer's loan quote that was acquired from your CalculateLoan Bean.
Remote Interface
The remote interface provides access to the entity bean's business logic, just like the session
bean's. With an entity bean, the most common remote interface contains accessor methods for
all of the bean's attributes. This way the client has the capability to set and get the value for
each attribute. This is common in many Java objects; the unique concept here is that changes
that are made are also made in the database.
The Quote remote interface is only going to provide the accessor methods. Listing 12.5 con-
tains the source for your Quote remote interface.
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Quote extends EJBObject
public void setCustomerName(String name) throws RemoteException;
public String getCustomerName() throws RemoteException;
public void setPhoneNumber(String phone) throws RemoteException;
public String getPhoneNumber() throws RemoteException;
public void setLoanAmount(Float amt) throws RemoteException;
public Float getLoanAmount() throws RemoteException;
public void setMonthlyPayment(Float pmt) throws RemoteException;
public Float getMonthlyPayment() throws RemoteException;
public void setInterestRate(Float rate) throws RemoteException;
public Float getInterestRate() throws RemoteException;
Search WWH ::

Custom Search