4 Replies Latest reply on Jan 3, 2008 10:57 AM by matt.drees

    POJO with conversational scope

    joris77

      I have a POJO that i want to use as a Seam bean with conversational scope and I have an entity "Person" that I store as an instance variable/javabean property on that POJO. Like this ...

      ...
      @Name("depot")
      @Scope(ScopeType.CONVERSATION)
      public class Depot {
      
       @Logger
       private Log log;
      
       private Person person;
      ...


      What I expect is that if the instance variable is set after the first request (I do that in my code) of the conversation that it remains there until the conversation is ended by the @End annotation of one of depot's action methods.

      Is this correct?

      In reality after the first postback from the client the instance variable is null.

      If I take a look in my logging I see that my javabean is created and destroyed each request:

      00:49:45,171 INFO [STDOUT] Constructing depot
      00:49:45,171 WARN [AbstractEntityManagerImpl] Calling joinTransaction() on a non JTA EntityManager
      00:49:45,171 INFO [Depot] Create depot
      00:49:45,234 WARN [AbstractEntityManagerImpl] Calling joinTransaction() on a non JTA EntityManager
      00:49:45,312 INFO [STDOUT] Hibernate: select material0_.id as id4_, material0_.version as version4_, material0_.created_by as created3_4_, material0_.created_on as created4_4_, material0_.last_modified_by as last5_4_, material0_.last_modified_on as last6_4_, material0_.description as descript7_4_, material0_.blocked as blocked4_, material0_.material_type as material11_4_, material0_.bar_code as bar9_4_, material0_.reason_for_blocking as reason10_4_ from material material0_ where material0_.bar_code=?
      00:49:45,359 INFO [STDOUT] Hibernate: select materialty0_.id as id5_0_, materialty0_.version as version5_0_, materialty0_.created_by as created3_5_0_, materialty0_.created_on as created4_5_0_, materialty0_.last_modified_by as last5_5_0_, materialty0_.last_modified_on as last6_5_0_, materialty0_.name as name5_0_, materialty0_.description as descript8_5_0_ from material_type materialty0_ where materialty0_.id=?
      00:49:45,406 INFO [STDOUT] Hibernate: select checkout0_.id as id1_, checkout0_.version as version1_, checkout0_.created_by as created3_1_, checkout0_.created_on as created4_1_, checkout0_.last_modified_by as last5_1_, checkout0_.last_modified_on as last6_1_, checkout0_.person as person1_, checkout0_.material as material1_, checkout0_.checkin_date as checkin7_1_, checkout0_.checkout_date as checkout8_1_ from checkout checkout0_ where checkout0_.material=? and (checkout0_.checkin_date is null)
      00:49:45,453 INFO [STDOUT] Hibernate: select person0_.id as id2_0_, person0_.version as version2_0_, person0_.created_by as created3_2_0_, person0_.created_on as created4_2_0_, person0_.last_modified_by as last5_2_0_, person0_.last_modified_on as last6_2_0_, person0_.last_name as last7_2_0_, person0_.middle_name as middle8_2_0_, person0_.initials as initials2_0_, person0_.bar_code as bar10_2_0_ from person person0_ where person0_.id=?
      00:49:45,531 WARN [AbstractEntityManagerImpl] Calling joinTransaction() on a non JTA EntityManager
      00:49:45,562 INFO [Depot] Destroy depot
      


      I am afraid I am missing the point here, somebody explain me how conversations are supposed to work?

      Do POJO conversations differ from EJB conversations?

      Thanks anyway,

      Joris Wijlens

        • 1. Re: POJO with conversational scope
          henrik.lindberg

          afaik - in order to have a long runningconversation you have to start it using @Begin, and then end it with @End.

          A default conversation is short.

          There are plenty of examples in both the documentation and in the example code that shows how to use longer conversations.

          • 2. Re: POJO with conversational scope
            joris77

            Henrik

            Thanks for your reply. I am sorry. I think I haven't been quite clear.

            There is one method with a @Begin anotation (doSomething) and two methods with an @End annotation. After the @Begin method is called and has returned to the client, the client does a postback (with a h:commandButton) to a method (doAnotherThing) on the bean. The instance variable person (annotated as an entity) has the value of null in doAnotherThing while it had been set to a non null value in the @Begin annotated method (doSomething).

            Like this

            ...
            @Name("depot")
            @Scope(ScopeType.CONVERSATION)
            public class Depot {
            
             @Logger
             private Log log;
            
             private Person person;
            ....
            
             @Begin
             public void doSomething(){
             person = ...;
             }
            
             public String doAnotherThing(){
             ... = person; // here the value of person is null
             }
            
             @End
             public void ......
            
            ...


            This is is logical when I compare this to the logging I get because the POJO is destroyed and recreated. But it doesn't meet my expectations for a conversation scoped component. I expect the component to be stored somewhere over requests.

            My most important question is are my expectations correct?

            Joris

            • 3. Re: POJO with conversational scope
              raoul.schmidiger

              Hi List,

              I got the same problem and it would be great if somebody could make things a little clearer. As our friend Joris, I have a bean annotated with

              @Scope(ScopeType.CONVERSATION)

              AND

              @Stateless

              As this bean contains entity (@Stateful) beans, my expectation towards a statless bean WITH conversation scope is that the very same bean is used throughout the conversation. Otherwise the conversation scope does not really make sense....

              HOWEVER, if I do not use the EJB annotation @Stateless, the thing works ???

              How do the EJB and the SEAM annotations interfere with each other?

              The problem is, that I need to annotate the bean with EJB as container classes (persistence context etc) have to be injected.....

              Thanks for any clarification on the issue.

              Regards raoul

              • 4. Re: POJO with conversational scope
                matt.drees

                Conversation-scoped EJBs should be @Stateful. IIRC, @Stateless beans will always be assigned to the Stateless pseudo-scope.