user manual
106 BES Developer’s Guide
bean methods in the same way that it invokes any method, such as its own
method summarize().
...
Cart cart;
{
...
// obtain a reference to the bean's remote interface
cart = home.create(cardHolderName, creditCardNumber, expirationDate);
}
// create a new book object
Book knuthBook = new Book("The Art of Computer Programming", 49.95f);
// add the new book item to the cart
cart.addItem(knuthBook);
...
// list the items currently in the cart
summarize(cart);
cart.removeItem(knuthBook);
...
Removing bean instances
The remove() method operates differently for session beans than for entity
beans. Because a session object exists for one client and is not persistent, a
client of a session bean should call the remove() method when finished with a
session object. There are two remove() methods available to the client: the
client can remove the session object with the javax.ejb.EJBObject.remove()
method, or the client can remove the session handle with the
javax.ejb.EJBHome.remove(Handle handle) method. Go to “Using a bean's handle”
on page 106 for more information on handles.
While it is not required that a client remove a session object, it is considered to
be good programming practice. If a client does not remove a stateful session
bean object, the container eventually removes the object after a certain time,
specified by a timeout value. The timeout value is a deployment property.
However, a client can also keep a handle to the session for future reference.
Clients of entity beans do not have to deal with this problem as entity beans
are only associated with a client for the duration of a transaction and the
container is in charge of their life cycles, including their activation and
passivation. A client of an entity bean calls the bean's remove() method only
when the entity object is to be deleted from the underlying database.
Using a bean's handle
A handle is an another way to reference an enterprise bean. A handle is a
serializable reference to a bean. You can obtain a handle from the bean's
remote interface. Once you have the handle, you can write it to a file (or other










