82
8.3. The Component Interface
8.3.1. Business Methods
The Component Interface is the client's view of an instance of the Entity Bean. It is what is returned
to the client by the Home interface after creating or finding an Entity Bean instance. This
interface contains the business methods of the Enterprise Bean. The interface must extend the
javax.ejb.EJBObject
local. The methods of a remote component interface must follow the rules for Java RMI. For
each method defined in this component interface, there must be a matching method of the bean
implementation class (same arguments number and types, same return type, same exceptions except
for RemoteException).
8.3.1.1. Component Interface Example
public interface Account extends EJBObject {
public double getBalance() throws RemoteException;
public void setBalance(double d) throws RemoteException;
public String getCustomer() throws RemoteException;
public void setCustomer(String c) throws RemoteException;
public int getNumber() throws RemoteException;
}
8.4. The Primary Key Class
The Primary Key class is necessary for entity beans only. It encapsulates the fields representing the
primary key of an Entity Bean in a single object. If the primary key in the database table is composed
of a single column with a basic data type, the simplest way to define the primary key in the bean is
to use a standard Java class (for example,
have the same type as a field in the bean class. It is not possible to define it as a primitive field (for
example, int, float or boolean). Then, it is only necessary to specify the type of the primary key in the
deployment descriptor:
prim-key-class java.lang.Integer /prim-key-class
And, for container-managed persistence, the field which represents the primary key:
primkey-field accno /primkey-field
The alternative way is to define its own Primary Key class, described as follows:
The class must be serializable and must provide suitable implementation of the
methods.
equals(Object)
For
container-managed persistence
The fields of the primary key class must be declared as public.
•
The primary key class must have a public default constructor.
•
The names of the fields in the primary key class must be a subset of the names of the container-
•
managed fields of the Enterprise Bean.
interface if it is remote, or the
java.lang.Integer
, the following rules apply:
Chapter 8. Developing Entity Beans
javax.ejb.EJBLocalObject
or
java.lang.String
if it is
). This must
and
hashcode()
Need help?
Do you have a question about the APPLICATION SERVER - JONAS and is the answer not in the manual?
Questions and answers