aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Stateful Session and Shopping Cart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateful Session and Shopping Cart" Watch "Stateful Session and Shopping Cart" New topic
Author

Stateful Session and Shopping Cart

Pawanpreet Singh
Ranch Hand

Joined: Jun 12, 2005
Posts: 264

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

Joined: Mar 22, 2007
Posts: 329

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 ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Pawanpreet Singh
Ranch Hand

Joined: Jun 12, 2005
Posts: 264

Thank you. What is annotation here you are talking about. Is this feature being used in EJB3.0.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

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.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateful Session and Shopping Cart