background image

The Remove Method

<< Business Methods | Deploying the cart Example >>
<< Business Methods | Deploying the cart Example >>

The Remove Method

The modifier must not be static or final.
The throws clause can include exceptions that you define for your application. The removeBook
method, for example, throws the BookException if the book is not in the cart.
To indicate a system-level problem, such as the inability to connect to a database, a business
method should throw a javax.ejb.EJBException. The container will not wrap application
exceptions such as BookException. Because EJBException is a subclass of RuntimeException,
you do not need to include it in the throws clause of the business method.
The Remove Method
Business methods annotated with javax.ejb.Remove in the stateful session bean class can be
invoked by enterprise bean clients to remove the bean instance. The container will remove the
enterprise bean after a @Remove method completes, either normally or abnormally.
In CartBean, the remove method is a @Remove method:
@Remove
public void remove() {
contents = null;
}
Helper Classes
The CartBean session bean has two helper classes: BookException and IdVerifier. The
BookException
is thrown by the removeBook method, and the IdVerifier validates the
customerId
in one of the create methods. Helper classes may reside in the EJB JAR file that
contains the enterprise bean class, or in an EAR that contains the EJB JAR.
Building, Packaging, Deploying, and Running the cart
Example
You can build, package, deploy, and run the cart application using either NetBeans IDE or the
Ant tool.
The cart Example
The Java EE 5 Tutorial · September 2007
662