8 Replies Latest reply on May 29, 2009 9:41 PM by Guillermo Ortiz

    Problem Staless with SCOPE.SESSION??

    Guillermo Ortiz Newbie

      Hello,


      I want to know the difference between an EJB Staless with SCOPE.SESSION a Stanful. 


      If I have an Stateless should not it save the attributes during all session, without sharing them with another SESSION of another user?


      Thanks.

        • 1. Re: Problem Staless with SCOPE.SESSION??
          Pedro Sena Newbie

          I don't know if I understood correctly.


          Are you using @Stateless and @Scope(Conversation)  together ?


          If so, you are making something wrong.


          If you want to keep state, do not use @Stateless, use @Stateful instead, and if you do so, you don't need to specify a @Scope for your EJB, it will be automatically registered as Conversation scope.


          HTH,


          Pedro Sena

          • 2. Re: Problem Staless with SCOPE.SESSION??
            Joshua Davis Expert

            Guillermo Perez wrote on May 29, 2009 14:09:

            I want to know the difference between an EJB Staless with SCOPE.SESSION a Stanful. 

            If I have an Stateless should not it save the attributes during all session, without sharing them with another SESSION of another user?


            You can use a Stateful EJB in the session context to store values that will be associated with the session in the fields of the SFSB.   Session points to SFSB, SFSB has fields with values.


            You can also use a Stateless EJB with fields that are injected from session scope (or any other scope) for a similar purpose.   Although Seam may use a random SLSB instance from the pool (with whatever values happen to be in the fields), the values will always be injected just before any method call, and outjected after every method call.  So here, the values are actually stored in the session scope, and the SLSB fields are reset every time.

            • 3. Re: Problem Staless with SCOPE.SESSION??
              Guillermo Ortiz Newbie

              Thaks all.


              I'm work with @Stateless and @Scope(SESSION).


              I don't know why sometimes the values attribute of the Stateless  lost or change for other values in different calls. I believe that it is a problem to work with @Scope(Session)


              If I was working with @Stateful, have I what to indicate explicitly where it @Begin the CONVERSATION and where it @End?. It can begin in a call an EJB and to finish in another EJB?

              • 4. Re: Problem Staless with SCOPE.SESSION??
                Israel Fonseca Apprentice

                You can't, or you shouldnt use a Stateless Session Bean scoped to session, thats not a bug. That's why you are having issues with atribute values. You should use the SSB if you want to keep your atributes.


                You dont have to put an @End, or @Begin. It's optional, but you have to put a method with @Remove. End, and Begin is up to your needings.


                • 5. Re: Problem Staless with SCOPE.SESSION??
                  Joshua Davis Expert

                  Israel Fonseca wrote on May 29, 2009 16:08:

                  You can't, or you shouldnt use a Stateless Session Bean scoped to session, thats not a bug. That's why you are having issues with atribute values. You should use the SSB if you want to keep your atributes.


                  Right, but like I had mentioned in my previous post you can use an SLSB (you are correct not in session scope!) with values injected from the session context.  I think some of the Seam examples use this technique, which might be confusing for a beginner.


                  For that reason I almost always use a Stateful EJB or a POJO for session scoped stuff.

                  • 6. Re: Problem Staless with SCOPE.SESSION??
                    Joshua Davis Expert

                    Guillermo Perez wrote on May 29, 2009 15:59:


                    Thaks all.

                    I'm work with @Stateless and @Scope(SESSION).

                    I don't know why sometimes the values attribute of the Stateless  lost or change for other values in different calls. I believe that it is a problem to work with @Scope(Session)


                    Stateless session beans should be application scope.   It doesn't make sense to have them in session scope.  The container has a pool of stateless instances and may give you a different instance every time.  You told the container this bean has no relevant state, so the container is free to give you any instance.


                    If you really don't like stateful beans, you can:



                    • Put the logic in a stateless bean, in application scope.

                    • Every field in the stateless bean must be dependency injected.

                    • Outject entites or other objects into session scope so the stateless bean will have something to inject.




                    That's the complicated way to do things.   Use a stateful EJB.  Your code will be easy to understand and maintain.

                    • 7. Re: Problem Staless with SCOPE.SESSION??
                      Guillermo Ortiz Newbie

                      I don't undestand..

                      If I've:

                      @Stateless
                      public class ClassA implements IClassA{
                       
                        @In(Scope.SESSION)
                        private List<X> listX


                      I understand, that the list is injecting of the SESSION  (HttpSession or similar). Why "sometimes" it does not have the correct value, or it loses the value being null?.

                      Another silly question:
                      I dont have  stateful. I dont have done in any site HttpSession.setAttribute(...).

                      With @In if I indicate that a scope of session knows wherefrom to take the value, but when it has set it in session if I have not done it...????
                      • 8. Re: Problem Staless with SCOPE.SESSION??
                        Guillermo Ortiz Newbie

                        If POJO and you put in the definition of class @Scope (Session)
                        I understand that any instance of this class stores in session, does it work this way, not? 


                        But the List the previous message?


                        Thank you very much to all