4 Replies Latest reply on Sep 24, 2010 5:30 AM by Shervin Asgari

    Stateless default scope type

    Shervin Asgari Master

      Hi.


      From SiA lists the scope that is used for each type of component if
      one is not specified in the component definition
      :



      EJB stateful session bean Conversation
      JPA entity class Conversation
      EJB stateless session bean Stateless
      EJB message driven bean Stateless
      JavaBean (POJO) Event



      Now this means that a @Stateless should have Stateless as default scope, however when I do @In on that with the scope present it doesnt work.


      ie:



      interface foo
      
      @Stateless 
      @Name("foo")
      @AutoCreate
      public class FooImpl implements Foo



      Now lets say in a class you try to inject foo. This works fine.



      @In Foo foo;



      Now lets say I want to specify the scope directly



      @In(scope=ScopeType.STATELESS) Foo foo;



      The latter fails! Why? Shouldn't the scopetype be stateless?


        • 1. Re: Stateless default scope type
          Arbi Sookazian Master

          I was able to reproduce the behavior using Seam 2.2.0.GA.  Here is the root cause:


          Caused by: java.lang.IllegalArgumentException: cannot specify explicit scope=STATELESS on @In: authenticator.foo
               at org.jboss.seam.Component.getValueToInject(Component.java:2314)
               at org.jboss.seam.Component.injectAttributes(Component.java:1736)
               at org.jboss.seam.Component.inject(Component.java:1554)
               at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
               at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:597)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
               ... 113 more



          Why is it illegal to specify explicit scope=STATELESS on @In?


          Additional experimentation reveals...


          @In(create=true, scope=ScopeType.CONVERSATION)
              private Foo foo;



          Caused by: java.lang.IllegalArgumentException: cannot combine create=true with explicit scope on @In: authenticator.foo
               at org.jboss.seam.Component.getValueToInject(Component.java:2307)
               at org.jboss.seam.Component.injectAttributes(Component.java:1736)
               at org.jboss.seam.Component.inject(Component.java:1554)
               at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
               at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:597)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
               ... 113 more



          Why is this illegal?

          • 2. Re: Stateless default scope type
            Shervin Asgari Master

            Hi Arbi, thanks for the reply.


            My guess is that (and this is kinda far fetched), maybe Seam in Action has a typo here? Maybe the information is incorrect. Perhaps the default scope of a @Stateless is something entirely different.

            • 3. Re: Stateless default scope type
              marcolof Newbie

              I ran into the same problem and ended up using the Seam Debug page to examine the content of the scopes:


              For some reason, the default scope of a @Stateless EJB is.. the Application Context???



              Seems like a bug to me! (I'm using 2.2.0.GA on a jBoss 5.1.0 GA server).
              Any of the Seam developers have an answer for us?



              Thanks!

              • 4. Re: Stateless default scope type
                Shervin Asgari Master

                Yes this is a bug, however it is not true that a stateless ejb is application context. Stateless ejb is Stateless. And the stateless scope is the first scope @In will search on. So its really no point in trying to speed things up by defining scope when it is stateless.