• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateful Session and Shopping Cart

 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I am playing around stateful session beans. So building a shopping cart simple demo for that. I am new to EJBs. So need to clear a doubt. We know Stateful session beans are used for more than one conversation between client and server. Here client is a Servlet. So when user first time enters or adds an item to cart, i fire a create(some arg, may be user name) and get a ref to remote component stub. Now item is added first time. and my first request to web client is done. The item is finally added in Session bean 's list.

We know that http is stateless. Next time, i cant get ref to remote component stub to the same bean. So do i need to store it into HttpSession for the same user session till the time user say confirm for all items and when user confirm, finally after buying those items, i need to call remove on ref to remote component stub or on home stub with Handle.

Please correct me if i am wrong here or tell me some good technique of this.

Thanks
Pawan
SCJP5.0, SCWCD 1.4
TARGET: EJB2.0 and the EJB3.0
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pawan,

I am new to EJB but I have also been thinking about servlets and session EJBs.

I think you are right: you need to store your stateful session bean's reference in the web application's session scope. Then when you are done using it, you should call one of the remove methods (e.g., one of the stateful session's beans methods annotated with the @Remove annotation) and then remove your stateful session bean's reference from session scope.
[ May 13, 2008: Message edited by: Sergio Tridente ]
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. What is annotation here you are talking about. Is this feature being used in EJB3.0.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pawan preet:
Thank you. What is annotation here you are talking about. Is this feature being used in EJB3.0.


Yes. With EJB 3, you just annotate your beans for the callbacks and actually much more.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic