2 Replies Latest reply on Feb 23, 2011 9:59 AM by abreumania

    How does weld long conversation works with seam managed persistence context?

    yangju.richard.yang.pearson.com
      Let's say I have a controller bean

      @Named
      @ConversationScoped
      public class FrontController implements Serializable{
         
          @Inject Conversation conversation;
          @Inject MySMPCService service;

          public void start(){
              conversation.begin();
              EntityA a = service.findEntityA();
          }
         
          public void doMore(){
              a.getChildEntity();
          }
      }


      @Transactional
      public class MySMPCService {
          @TestDBRepo
          @SeamManaged
          @ConversationScoped
          @Produces
          @PersistenceUnit(unitName = "test")
          EntityManagerFactory emf;
         
          @Inject EntityManager em;
         
          public EntityA findEntityA(){
             
              EntityA a = em.find(EntityA, 1);
          }
      }

      When the doMore() is called, I found that the Persistence Unit is closed, therefore I got lazyInitialization exception on the EntityA's child. I expected that since seam knows that there is a conversation context by weld, the SMPC would stay open until the Frontcontroller ends the conversation. But it appears that the SMPC is closed as soon as the method call in service is terminated.

      Is my understanding wrong?
      We really want the PC only to be used in the service layer and the controller has no knowledge of PC.

      Anybody please give me some explanation?

      Thanks.