View RSS Feed

My Java Tips

@Stateful (Stateful session bean)

Rate this Entry
by , 11-03-2011 at 06:34 PM (1669 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:
@Stateful(entityContext=INSTANCE)
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;
}
@Remove
public Bid bidForItem(User user, BigDecimal amount) {
return item.bid(user, amount);
}}

Submit "@Stateful (Stateful session bean)" to Facebook Submit "@Stateful (Stateful session bean)" to Digg Submit "@Stateful (Stateful session bean)" to del.icio.us Submit "@Stateful (Stateful session bean)" to StumbleUpon Submit "@Stateful (Stateful session bean)" to Google

Tags: None Add / Edit Tags
Categories
EJB , Java EE

Comments