10 Replies Latest reply on May 20, 2009 3:53 PM by oneworld95

    Difference between Stateful and SESSION scope

    oneworld95

      This is a completely newbie question: What's the difference between the Stateful and SESSION scope annotations on a session bean? Thanks.

        • 1. Re: Difference between Stateful and SESSION scope

          Stateful is for EJBs, SESSION is for Pojos... What is the difference between EJBs and POJOs you ask? read that here.

          • 2. Re: Difference between Stateful and SESSION scope
            gavin.king

            @Stateful makes it a stateful session bean - one that can hold client-visible state.


            @Scope(SESSION) defines the scope of that state, in this case scoped to the HTTP session, instead of some other scope like request or conversation.

            • 3. Re: Difference between Stateful and SESSION scope
              gavin.king

              Stateful is for EJBs, SESSION is for Pojos

              No, @Scope(SESSION) has nothing to do with whether something is an EJB or not.

              • 4. Re: Difference between Stateful and SESSION scope

                Gavin King wrote on May 19, 2009 23:33:


                Stateful is for EJBs, SESSION is for Pojos

                No, @Scope(SESSION) has nothing to do with whether something is an EJB or not.



                Agreed, you can use @Scope(SESSION) with an EJB (but you can not use @Stateful with POJOs)





                • 5. Re: Difference between Stateful and SESSION scope

                  Gavin King wrote on May 19, 2009 23:32:


                  @Stateful makes it a stateful session bean - one that can hold client-visible state.



                  I do not see anything about client-visibility here. The definition is: Component-defining annotation for a stateful session bean. . Maybe I am wrong but session beans have, by default (in projects without Seam) a scope that is very similar (what is the exact difference I really would like to know) to the one specified by @Scope(SESSION)



                  @Scope(SESSION) defines the scope of that state, in this case scoped to the HTTP session, instead of some other scope like request or conversation.





                  And the scope for an EJB annotated with @Stateful is...





                  • 6. Re: Difference between Stateful and SESSION scope
                    nickarls

                    Whatever you @Scope it to or



                    When no scope is explicitly specified, the default depends upon the component type. For stateless session beans, the default is STATELESS. For entity beans and stateful session beans, the default is CONVERSATION. For JavaBeans, the default is EVENT.

                    PS. Try to write your own comment outside the quote block. It's hard to see what you wrote (or people think you just quoted everything add mistakenly pressed Save before adding anything)

                    • 7. Re: Difference between Stateful and SESSION scope

                      Nicklas Karlsson wrote on May 20, 2009 10:59:


                      Whatever you @Scope it to or

                      When no scope is explicitly specified, the default depends upon the component type. For stateless session beans, the default is STATELESS.



                      Ok, just to avoid confusion, what is, from a behavior point of view, the difference between @Stateless and STATELESS ?



                      For entity beans and stateful session beans, the default is CONVERSATION. For JavaBeans, the default is EVENT.


                      Ok, but if I ommited the @Name (if my EJB were not a Seam component). How would its scope behave? as if it were SESION?



                      PS. Try to write your own comment outside the quote block. It's hard to see what you wrote (or people think you just quoted everything add mistakenly pressed Save before adding anything)



                      Ar you sure was using blockquote it wrong? (My words are inside a quoteblock inside the main quoteblock and they appear with a darker background, I thought that was enough to distinguish them). Are you saying that I should always delete the main quoteblock? should I write what you wrote inside the blockquote as I am doing now? (Because you used blockquotes inconsistently in you last post.. did you notice ? ;-)



                      • 8. Re: Difference between Stateful and SESSION scope
                        christian.bauer

                        backwards.

                        reading your postings

                        it feels like

                        Yes, because





                        You did it right for the first time now. The stuff you are quoting from the previous poster goes inside <blockquote>. Your text is the only one that should not be inside <blockquote>. Why would you quote would you just said?

                        • 9. Re: Difference between Stateful and SESSION scope
                          swd847

                          If it were not managed by seam then the client would have to manually manage its lifecycle, the client obtains a reference using JNDI lookup and frees the reference by calling the @Remove lifecycle method.

                          • 10. Re: Difference between Stateful and SESSION scope
                            oneworld95

                            Thank you all for your replies. Much appreciated.