1

I need to call a method annotated with @Asynchronous in EJB from a ConversationScoped bean. Inside this method I create instances of some classes using @Inject to inject ConversationScoped beans. Is it somehow possible to set the context of the asynchronous method to given Conversation?

I hope you can help me.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
red13
  • 427
  • 4
  • 12

1 Answers1

3

No, absolutely not. EJBs do per definition not run in web container, but in EJB container. In essence, having any web-related artifact/dependency (including javax.faces.* classes) inside an EJB class is a red alert. You're not supposed to inject/access any class from the client tier (the WAR) in the business tier (the EJB/EAR). Moreover, conversation scoped beans are tied to a HTTP request parameter and this information is nowhere available in an EJB container.

Whatever problem you're trying to solve and for which you incorrectly thought that this all would be the right solution, it has to be solved differently. As an educated guess, I think you just need to let the EJB fire a CDI event or take a callback argument.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for your detailed answer. Sadly the project is too complex to change such essential implementations. There are indeed EJB classes annotated with ConversationScoped. So for now there is no solution for this problem. We should think about removing ConversationScoped first. – red13 May 07 '15 at 06:24
  • The Conversation is managed by CDI, but is lost when I call synchronous in an EJB-Bean – red13 May 07 '15 at 07:42
  • If you intend to tie a stateful EJB instance to a specific HTTP conversation, then you should use a `@Stateful` bean and inject it in the `@ConversationScoped` bean. Another food for read: http://stackoverflow.com/q/8887140 – BalusC May 07 '15 at 07:45