Question

We inject EntityManager into Bean (located inside Service Layer) as below:

@Inject

EntityManager entityManager

And We use these services inside ManagedBean (located inside view layer). Everything works fine.

The problem occurs when we inject these services inside Stateless WebService. EntityManager injected in Stateless WebService using same way with above code. Because of my entityManager is ConversationScoped, we are getting following error:

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped
    at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:598) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

How can we solve this problem? How can we use same services inside both View Layer and WebServices Layer?

Was it helpful?

Solution

There is no Conversation scope available for web services, it's been covered quite a bit on SO (don't recall links right now). Either create your own scope which will work regardless, or move down to a Request Scoped EM.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top