Forums Register Login

Getting Stateful EJB after @Remove-method

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 will suppress my every urge. But not this shameless plug:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1324 times.
Similar Threads
Stateful Session Bean - Conversational State
One more question about stateful beans
shopping cart for FBN
Update cart asynchronously please
ETS Question on session bean
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:31:04.