View RSS Feed

My Java Tips

@Stateful (Stateful session bean)

Rate this Entry
by , 11-03-2011 at 07:34 PM (2152 Views)
@Stateful annotation is used to represent stateful session bean. These beans are used to maintain conversational state across method invocations, then use stateful session beans. As the name implies, these beans maintain the internal state. For instance: Online shopping is an example of stateful session bean. We need to maintain the state of the bean when the customer adds/removes items from the cart.

An example of stateful session bean is presented below:

Java Code:
public class AuctionFacadeImpl implements AuctionFacade {
private Item item;
private ItemDAO itemDAO;
@Inject public void setItemDAO(ItemDAO dao) {
this.itemDAO = dao;
public Item getItem(Long itemId) {
item = itemDAO.findById(itemId);
return item;
public Bid bidForItem(User user, BigDecimal amount) {
return, amount);

Submit "@Stateful (Stateful session bean)" to Facebook Submit "@Stateful (Stateful session bean)" to Digg Submit "@Stateful (Stateful session bean)" to Submit "@Stateful (Stateful session bean)" to StumbleUpon Submit "@Stateful (Stateful session bean)" to Google

Tags: None Add / Edit Tags
EJB , Java EE