Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Stateful EJB after @Remove-method

 
Valentin Shannon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic