2 Replies Latest reply on Jul 18, 2012 9:25 AM by Hadar Grubman

    transaction of application scoped bean

    Hadar Grubman Newbie

      I am trying to understand how seam manages transactions in the following case:

       

      I have an Application scoped bean :

      @Name("bean")
      @Scope(ScopeType.APPLICATION)
      @Synchronized
      public class MyBean {
       
           @PersistenceContext
           private EntityManager em;
       
           public void foo() {
                // using em...     
           }
      }
      

       

      And i have two different session scoped beans that each has it's own transaction and uses MyBean as a util.

       

      The question is, when the faunction foo() will be invoked, which transaction will be held by em? the one of the calling session scoped bean? or a third new and not related transaction?

       

      Thanks ahead!

        • 1. Re: transaction of application scoped bean
          Hadar Grubman Newbie

          just to clarify, my intention is that foo() will commit its cahnges to the db whitout commiting the changes that ware made so far by the calling session scoped bean. In addition i'll want that both beans will see the cahnges.

          • 2. Re: transaction of application scoped bean
            Hadar Grubman Newbie

            I found the answer, it was quite simple actually...

             

            you cannot use @PersistenceContext in an application scoped bean.

             

            The only possible implementation is as follows:

             

             

            @Name("bean")
            @Scope(ScopeType.APPLICATION)
            @Synchronized
            public class MyBean {
             
                 public void foo(EntityManager em) {
                      // using em...     
                 }
            }
            

             

            And in that case, its clear that that calling session scoped bean will send its own EM and by that the transaction in foo will be the sane as the transaction of the calling bean.