13 Replies Latest reply on Nov 9, 2009 3:04 PM by Denis Forveille

    InjectionException in WebSphere with SFSB

    Chris Ouellette Newbie


      I've read the reference documentation for WebSphere and have several application running under it successfully. I'm now working on a new application and I want to use Stateful Session Beans.

      Here is my persistence.xml:

      <persistence-unit name="myDB" transaction-type="JTA">
                <property name="hibernate.show_sql" value="false" />
                <property name="hibernate.transaction.flush_before_completion" value="false" />
                <property name="hibernate.cache.provider_class"
                     value="org.hibernate.cache.HashtableCacheProvider" />
                <property name="hibernate.dialect"
                     value="org.hibernate.dialect.DB2Dialect" />
                <property name="hibernate.transaction.manager_lookup_class"
                     value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />

      Despite setting the hibernate.transaction.flush_before_completion property to false, I still get the error below after about 10 minutes:

      A NamingException is being thrown from a javax.naming.Context implementation. Details follow:
      Context implementation: com.ibm.ws.naming.java.javaURLContextRoot
      Context method: lookup(Name)
      Context name: java:
      Target name: comp/EJBContext
      Other data: ""
      Exception stack trace: com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is com.ibm.wsspi.injectionengine.InjectionException: EJBContext may only be looked up by or injected into an EJB]
           at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1021)
           at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:191)
           at com.ibm.ws.naming.java.javaURLContextRoot.processBoundObjectForLookup(javaURLContextRoot.java:407)
           at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1280)
           at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:384)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:204)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:144)
           at javax.naming.InitialContext.lookup(InitialContext.java:363)
           at org.jboss.seam.util.EJB.getEJBContext(EJB.java:89)
           at org.jboss.seam.transaction.Transaction.createCMTTransaction(Transaction.java:69)
           at org.jboss.seam.transaction.Transaction.getTransaction(Transaction.java:53)
           at sun.reflect.GeneratedMethodAccessor430.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:618)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
           at org.jboss.seam.Component.unwrap(Component.java:2275)
           at org.jboss.seam.Component.getInstance(Component.java:2041)
           at org.jboss.seam.Component.getInstance(Component.java:2000)
           at org.jboss.seam.Component.getInstance(Component.java:1994)
           at org.jboss.seam.Component.getInstance(Component.java:1967)
           at org.jboss.seam.Component.getInstance(Component.java:1962)
           at org.jboss.seam.transaction.Transaction.instance(Transaction.java:39)
           at org.jboss.seam.contexts.Contexts.flushAndDestroyContexts(Contexts.java:331)
           at org.jboss.seam.contexts.Lifecycle.endCall(Lifecycle.java:96)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:122)
           at org.jboss.seam.intercept.RootInterceptor.invokeAndHandle(RootInterceptor.java:84)
           at org.jboss.seam.intercept.SessionBeanInterceptor.prePassivate(SessionBeanInterceptor.java:56)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:618)
           at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227)
           at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:526)
           at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle(InvocationContextImpl.java:231)
           at com.ibm.ejs.container.StatefulBeanO.passivate(StatefulBeanO.java:1083)
           at com.ibm.ejs.container.StatefulBeanO.uninstall(StatefulBeanO.java:1485)
           at com.ibm.ejs.container.activator.StatefulSessionActivationStrategy.atTimeout(StatefulSessionActivationStrategy.java:611)
           at com.ibm.ejs.container.activator.Activator.timeoutBean(Activator.java:851)
           at com.ibm.ejs.container.StatefulBeanReaper.deleteBean(StatefulBeanReaper.java:468)
           at com.ibm.ejs.container.StatefulBeanReaper.sweep(StatefulBeanReaper.java:295)
           at com.ibm.ejs.container.StatefulBeanReaper.alarm(StatefulBeanReaper.java:252)
           at com.ibm.ejs.util.am._Alarm.run(_Alarm.java:90)
           at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)

      Is anyone else still getting this error in WebSphere even after they set up their properties correctly in persistence.xml? Anything else I should be looking at? Let me know if you want to see the code of my SFSB.



        • 1. Re: InjectionException in WebSphere with SFSB
          Chris Ouellette Newbie

          Just to clarify, I'm running Seam 2.1.2 with DB2 v8.1

          • 2. Re: InjectionException in WebSphere with SFSB
            Dhina Alb Newbie

            I am getting the same error as well.  Any help appreciated.
            Thanks in advance

            • 3. Re: InjectionException in WebSphere with SFSB
              Chris Ouellette Newbie

              Hi Dhina,

              What environment are you running in? What WebSphere version, Seam version, etc.?

              Also, what is your application structure? Are you injecting Stateful beans into each other?

              Did you follow all of the setup instructions regarding persistence.xml as provided in the WebSphere reference docs?


              • 4. Re: InjectionException in WebSphere with SFSB
                Anton Savin Newbie

                It's a known issue/feature of WAS: it has a 10-minute timeout for stateful session beans. To make you love Websphere even more you can't amend this value globally: You cannot set the timeout globally or on a server basis. You can only set the timeout on a bean-by-bean basis.

                • 5. Re: InjectionException in WebSphere with SFSB
                  Denis Forveille Novice

                  We have many applications running perfectly well on WAS v7.0.0.3 and Seam 2.1.2

                  About your problem, create a file in your ejb project called META-INF/ibm-ejb-jar-ext.xml and add an entry for each SFSB like this to define the timeout of each SFSBs:

                  <?xml version="1.0" encoding="UTF-8"?>
                       xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-ext_1_0.xsd"
                     <session name="<SFSB name, ie CompteManagerImpl>" >
                        <time-out value="<timeout in secs must be greater that you conv timeout>" />

                  In persistence.xml you don't need "non-jta-data-source" nor "hibernate.transaction.flush_before_completion"

                  As for the setup of your seam project in WebSphere of JNDI resolution, search this forum for my posts about the subject (clue: look for the usage of @JndiName annotation, a for a file named seam-jndi.poperties)

                  • 6. Re: InjectionException in WebSphere with SFSB
                    Chris Ouellette Newbie

                    Hi Denis, thank your for your response.

                    I have tried setting up the  ibm-ejb-jar-ext.xml file and haven't had any luck. Here is my file:

                    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-ext_1_0.xsd"
                    <session name="AuthenticatorServiceImpl"><time-out value="1800000"/></session>
                    <session name="SearchServiceImpl"><time-out value="1800000"/></session>
                    <session name="UserServiceImpl"><time-out value="1800000"/></session>

                    I've tried with the implementation name as well as the interface name without any luck.

                    Do you have any entries in your ejb-jar.xml or ejb-jar-bnd.xml that reference your SFSB's?

                    Also, WebSphere version may be the reason. I've talked with somebody at the WebSphere Community blog about this issue and they've told me that while they have included timeout support in Version 7, Version 6.1 was not designed to support configuring all the IBM extensions on EJB 3.0 beans.

                    And thanks for your notes on the JNDI resolution. Using @JndiName with the seam-jndi.properties has solved any lookup problems that I've faced.

                    Without any further guidance, I'm going to assume that my options are to either
                    A) Upgrade from WAS 6.1 to WAS 7
                    B) Revert back to using POJO's for my stateful components in this application.

                    • 7. Re: InjectionException in WebSphere with SFSB
                      Denis Forveille Novice

                      Did you remove the non-jta-data-source and hibernate.transaction.flush_before_completion clause from your persistence.xml file?

                      Configuring timeout for SFSB has to be done sice SFSB they are supported in websphere...

                      On the way to configure timout for SFSB in WAS v7, I opened a PMR on this a few months ago and the official answer is that there is no way to globally configure it at the cluster/server/application/jar level, nor to do it via an IBM specific annotation. They may consider this in a future FP/release. Currently the only way is to do it as described above.

                      As for WAS version, our apps runs on WAS v7.0.0.3 (Must be this version -at least- or you'll face various problems), not on WAS v6.1 so i cannot comment on this.

                      And no we don't have any ejb-refs in ejb-jar-bnd.xml (we even don't have this file, just the ejb-jar and the -ext files). The only ref we have is in web.xml from EjbSynchronisations to org.jboss.seam.transaction.LocalEjbSyncronisations

                      IMHO, you should try to upgrade to WAS v7.0 if you have the possibility to do so

                      • 8. Re: InjectionException in WebSphere with SFSB
                        Chris Ouellette Newbie

                        From IBM's mouth to our ears:

                        If the stateful session bean (SFSB) can no longer be accessed after 10 minutes of inactivity, the bean is timing out.  The time out value for a SFSB can not be set for an EJB 3.0 SFSB in the EJB 3.0 FeP.  This is a limitation of the EJB 3.0 FeP and this limitation is documented here.

                        In this doc, see the very last bullet and table in the section titled EJB component bindings and extensions.  In v7.0, an SFSB in an EJB   
                        3.0 module can have a timeout value defined on it.  The default timeout for an SFSB is 10 minutes.

                        • 9. Re: InjectionException in WebSphere with SFSB
                          Denis Forveille Novice

                          You're right.
                          When I said SFSB timeout configuration exist since SFSB exist in WAS, it is true for EJB 2.x and 3.x EXCEPT for the EJB3 FP available for WAS v6.1.

                          BTW, I have committed on the trunk a new version of the WebSphere configuration chapter focused on how to configure Seam for WAS v7 (including a section on how to configure the SFSB timeout, the different ways to configure JNDI names etc..)

                          I have also reviewed the jee5/booking sample app and committed a specific WAS v7 build file and WAS v7 specific config files, and also done some corrections on the jpa samples applications.
                          It will be included in v2.2.1, and until the v2.2.1 snapshot is downloadable, you can get it from svn

                          You can now just run the build file and deploy on WAS v7 the jee5/booking sample app as-is

                          • 10. Re: InjectionException in WebSphere with SFSB
                            John Eckhart Newbie

                            Setting the timeout value on SFSB can mitigate this problem some of the time, but it does not solve the problem. While you can set the timeout to a high value and destroy the bean manually, the timeout mechanism is meant to provide functionality and scalability. The problem is Seam is trying to look up the EJB context outside of an EJB (which is unsupported by WebSphere). Is there a way to defer this lookup to the EJB that Seam registers in jboss-seam.jar so that the SFSB may gracefully timeout?

                            • 11. Re: InjectionException in WebSphere with SFSB
                              Denis Forveille Novice

                              For us, SFSBs are always gracefully destroyed, i.e when the conversation they are attached to ends. We never eithere or create manually a SFSB, Seam is doing all the job.

                              We don't have any such problems  with seam 2.2.1-SNAPSHOT and WAS v7.0.0.5 (ie Seam trying to lookup for an SFSB in an unsupported way)

                              Do you have a scenario as an example? The only one I could  think of is the usage of the @Destroy annotation that may cause this (We don't use this annotation as we don't have the usage of it...)

                              • 12. Re: InjectionException in WebSphere with SFSB
                                Denis Forveille Novice

                                We've been finally hit by the EJBContext may only be looked up by or injected into an EJB exception during passivation/expiration OF SFSB by WAS.

                                I've reproduced the problem with this very simple SFSB in WAS v7.0.0.5 (Only 1 SFSB, no Seam at all...):

                                public void prePassivate() {
                                   System.out.println("PrePassivate called");
                                   try {
                                      InitialContext iCtx = new InitialContext();
                                      EJBContext eCtx = (EJBContext) iCtx.lookup("java:comp/EJBContext");
                                   } catch (NamingException e) {

                                With this method we receive the exception when the SFSB expire or is passivated.

                                So the problem is not in Seam but in WAS as the EJB 3 specs in section 12.2 Interceptor Life Cycle says that it muts be possible to perform an EJBContext in callback methods

                                I have opend a PMR by IBM (33753.077.649)

                                I will keep you informed of the status of this PMR

                                • 13. Re: InjectionException in WebSphere with SFSB
                                  Denis Forveille Novice

                                  IBM has created an APAR for the problem: PK98746

                                  With this APAR, callback methods (ie prePassicate etc...) can peform a lookup on java:comp/EJBContext as it is specified in the EJB3 specs.

                                  I've tested the fix with our apps and it works.

                                  The fix is planned to be included in WAS v7.0.0.9

                                  In the meantime, please contact IBM to get the fix for PK98746.