wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Getting Stateful EJB after @Remove-method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Getting Stateful EJB after @Remove-method" Watch "Getting Stateful EJB after @Remove-method" New topic
Author

Getting Stateful EJB after @Remove-method

Valentin Shannon
Greenhorn

Joined: May 05, 2012
Posts: 1
Hi Guys (and Ladies of course ;-) )!

I stumbled upon a jee6-tutorial (link to tutorial) where a shopping-cart is used as an example for a stateful session bean. There I learned something about the @Remove annotation. Within this example the checkout is "done" (in fact nothing happens in the code ) via a method annotated with @Remove.

The problem: As far as I know you cannot use the stateful session bean anymore after you have called the method with the @Remove annotation --> further calls on the same instance will result in an javax.ejb.EJBNoSuchObjectException. In my opinion the default-behavior of a shopping-cart should be that the old one is processed and afterwards an empty new one should be available. Therefore I was wondering about the following scenario:



The SessionController is a CDI-managed-bean used in a JSF-page. The ShoppingCart is my stateful session bean with the @Remove-method checkout(). After I have called the checkout()-method I cannot use the injected instance of ShoppingCart anymore and therefore I have to start a completely new browser-session which generates a new session for JSF which further injects a new instance of my ShoppingCart.

So the question is:
Is there a way to get a new instance of ShoppingCart injected via a standardized way (dependency injection)?

Thanks for your help in advance,
kind regards, Valentin
Christian Kindler
Greenhorn

Joined: Apr 16, 2009
Posts: 18
If you want a shopping card after checkout, keep the old one. Do not use @Remove, just make sure that your shopping card is empty after checkout. The example from the tutorial simply shows you that there is a @Remove annotation and how it is/can be used. But it might not be the best solution for the functional problem.

Regarding your technical question
Is there a way to get a new instance of ShoppingCart injected via a standardized way (dependency injection)?


I would be surprised if there is one and how it would fit in the lifecycle.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Stateful EJB after @Remove-method
 
Similar Threads
Stateful Session Bean - Conversational State
ETS Question on session bean
One more question about stateful beans
shopping cart for FBN
Update cart asynchronously please