3 Replies Latest reply on Apr 9, 2007 7:30 AM by christian.bauer

    @In or @PersistenceContext for EntityManager?

    waynebagguley

      I'm confused (having read the docs) over whether I should be using @In or @PersistenceContext for a Seam managed persistence context. What's the difference?

        • 1. Re: @In or @PersistenceContext for EntityManager?

          @PersitenceContext - Application Server creates EntityManager.
          Advantage: No Seam dependency -> portable.

          @In - Seam creates the EntityManager
          Advantage: Transaction management, is required for other Seam components like the entity converter.

          Regards

          Felix

          • 2. Re: @In or @PersistenceContext for EntityManager?
            kruno

            If you are using @In then you need to configure JPA http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/persistence.html#d0e5419
            It means that seam will manage your EntityManager and you will just inject it.
            Benefit of that is that you actualy use one EntityManager in side conversation, it is a great thing if you need to span one "hiberante session" between many actionBeans beacuse you than you do not have to merge things in side your context when you whant to persist them and so on it is truly session per conversation pattern, great thing I love it.
            On the other hand if you use @PersistenceContext than it is EJB stuff and and EntityManager is unique for on ActionBean only.
            I was confused about that to maybe this van help also
            http://www.jboss.com/index.html?module=bb&op=viewtopic&t=106004

            • 3. Re: @In or @PersistenceContext for EntityManager?
              christian.bauer

               

              "Kruno" wrote:
              On the other hand if you use @PersistenceContext than it is EJB stuff and and EntityManager is unique for on ActionBean only.


              That is not entirely correct. A Seam-managed persistence context is handled by Seam in the sense that its beginning and end is automatically the same as the "current" conversation (either a temporary conversation or a long-running conversation that spans several requests). This is very convenient.

              The EJB-container managed persistence context is on the other hand bound to the lifecycle of its owner, a stateful session bean. It's also only injected into components that are called within the same transaction context. The Seam-managed persistence context is injected into whatever components are called in the current conversation, no matter if there is a transaction going on or not.

              This has been discussed several times on the forum already, just search for it.