How to create a Stateful Session Bean

A stateful session bean can store information between client calls, as opposed to stateless session beans that cannot remember anything about the user from its last call.
A stateful session bean looks like an ordinary Java class except that it is annotated with the @Stateful annotation.
The typical stateful session bean is a shopping cart which keeps track of items that the user has added duing it’s visit to a particular site.
Below is an example of how a shopping cart stateful session bean could be declared:

As with a stateless session bean, the stateful session bean implements an interface – in this case the local interface that states what methods are to be implemented.
The stateful session bean may implement both local and remote interfaces. The local interfaces are used to call the bean within the same enterprise application.
The remote interface is used to call the session bean remotely, for example from another enterprise application located on another server or by a client application.
Below both interfaces are implemented. Note that we have added the annotations @Local and @Remote.

Business methods (read your methods) are then added to the Stateful Session Bean and the respective interfaces.

Search for more Java info on this site here:
Custom Search

Please type any questions here.