Entity Beans  «Prev  Next»

Lesson 1

Client view of Entity Beans

This module introduces the client side of entity beans.

Creating the bean instance

You will be introduced to the lookup of the home interface from JNDI.
Using the home interface, you will see how the bean instance, and the underlying data, can be created.

Finding an instance

For data that exists, you will learn to use the findByPrimaryKey() method of the home interface to locate the data and load it into the bean.

Business methods

You will learn to use the EJBObject reference returned by the findByPrimaryKey() to invoke the business methods of the bean and remove the bean.

Customer bean example

The examples in this part of the course use a Customer bean and client. The customer table, which is very simple, is created with the SQL command as follows:

create table customer(
custnum varchar(10) primary key,  
name varchar(25)
);
It has two columns labeled custnum and name. In the real world, it would have more columns. To keep the code simple it uses a Java String for the primary key. In practice, it would be an integer or something more complex. The remote interface of the Customer bean is as follows:
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Customer extends EJBObject {
public void setName(String name) throws RemoteException;
public String getInfo() throws RemoteException;
// returns custnum and name
}

Course project

The last part of this module is the course project where you will write the client of an entity bean.
The next lesson explores creation of an entity bean.