users@glassfish.java.net

Re: Embedded EJBContainer fails to instantiate when SSB is also a WebService

From: N W <emailnbw_at_gmail.com>
Date: Tue, 30 Aug 2011 16:46:08 -0400

Hi Bhakti -

OK, that's unfortunate. I'm surprised this is unsupported given the javaee6 1st cup sample code comes with a @Singleton @WebService example. Would this sample code not work in the embedded container?

Originally I had this class annotated simply as a @WebService and was injecting my EJBs. The @WebMethod was using several of these injected EJBs and propagating the results. eg.

Foo myFoo = myEJB1.getFoo();
Bar myBar = myEJB2.createBar(myFoo);

However, this was causing me problems with the transaction manager because myFoo was being detached in between finding it and passing into myEJB2 since the the calling method (@WebMethod) was not part of the EJBs persistence context. So to deal with that I added @Stateless to the @WebService class. That fixed the TX issues but broke the unit tests that try to instantiate the embedded container.

As a work-around I created an EJB that wraps the other EJB calls and then I have the WebService inject the 'wrapper' EJB and call the wrapper method on it. Ugly but works and now my tests work too.

-Noah

On Aug 30, 2011, at 3:41 PM, Bhakti Mehta wrote:

> I checked with Marina too and as of now this is not supported for Embedded EjbContainer and Stateless Webservice . I think when packaged in a war we had a bug in 3.1 which was causing it to behave as a webapp and I suspect may be that is why it is working in 3.1 when packaged in war.
> Regards,
> Bhakti