5 Replies Latest reply on Apr 3, 2006 1:43 PM by gavin.king

    Stateless bean in EVENT scope

      I mistakenly annotated one of my Seam classes as Stateless and then applied it to the EVENT Seam scope. Clearly this is not correct and I've since fixed it such that the component is now stateful. Here is my original code.

      @Stateless // <-- This should have been @Stateful
      @Scope(ScopeType.EVENT)
      @Name("browseAccountBean")
      @Interceptors(SeamInterceptor.class)
      public class BrowseAccountBean implements Serializable, BrowseAccount {
      ...
      }
      


      The bean was remembering state over multiple requests which is not surprising in hindsight and was confusing until I spotted the bug.

      Perhaps Seam should have picked up on my bad annotations and thrown an exception? (not that Seam is to blame)

        • 1. Re: Stateless bean in EVENT scope
          eekboom

           

          I mistakenly annotated one of my Seam classes as Stateless and then applied it to the EVENT Seam scope.

          It is my impression that @Scope is always ignored on stateless session beans.
          So yes, I think it would be nicer if seam gave at least a log message on warning level if the scope annotation is present at all.

          But in fact your mistake is unrelated to seam and the @Scope annotation, isn't it?
          You put state in a stateless bean that should have been a stateful bean.

          But maybe I have not understood something correctly.

          • 2. Re: Stateless bean in EVENT scope

            Yes, that's correct. I made a mistake and the bean was intended to be stateful. I was surprised that Seam didn't pick up on this as it seems to notice other incorrect annotations and halts deployment.

            Perhaps I am expecting too much of frameworks: should annotation based frameworks validate annotation usage? how should they react to any silly usages? is such validation expensive?

            I think my bad use of the @Scope annotation was an easily made mistake. I would rather the application was not deployed than deployed like this.

            Another mistake I made previously was to give two components the same name (@Name) in the same scope. This also led to strange behaviour. Again, is this something Seam should pick up on?

            • 3. Re: Stateless bean in EVENT scope
              gavin.king

              Well, it's arguable.

              It is actually OK to cache the reference to the stateless bean in SESSION or EVENT scope. What is not OK is to use the stateless bean to hold state...

              • 4. Re: Stateless bean in EVENT scope
                eekboom

                I am currently writing a plugin for IntelliJ Idea that catches these errors early on.

                Gavin, so @Scope on @Stateless beans is actually ok, and used by Seam, right? Then I will probably only give a warning on that.

                Shameless hijacking of the thread: Could you or some other expert maybe answer another questions about scope:
                http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3934456

                Thanks a lot.

                • 5. Re: Stateless bean in EVENT scope
                  gavin.king

                  Yes, a warning is fine.

                  Looking forward to seeing your plugin! :-)