4 Replies Latest reply on Jan 9, 2008 7:01 PM by Pete Muir

    Seam contexts and stateful session instances

    Cyrill Rüttimann Newbie


      I discovered a behaviour while implementing a simple page to edit an entity bean which I can not explain what happens is right or not.

      I expect:
      My stateful session bean has the following annotations:


      and the following method to load the customer I like to edit in the page:

       public void loadCustomer() {

      and the method to persist the changes:

      public String persistChanges() {

      So I expect, that I get an instance of the stateful session bean on which I call all three methods. But in reality, the method loadCustomer will be called more than once because I get another instance of the session bean (hash code) for loading the page and for saving the page. In addition, the instance also differs for saving the entity bean; reading the hash code of the bean instance in persistChanges(), the create annotated method gives me another hash code than the final instance in persistChanges. As far as I know, this behaviour is OK for J2EE because you do not care what instance you receive (instance pooling).

      But I expected, that the seam context annotation for event or conversation should give me the same instance of the bean? It would be helpful for me if someone explain me about the relationship of the seam context's and their relation to the stateful session bean instances.

      The business case works - the changed values will be persisted, but for me the create annotated method should only be called once ...