1 Reply Latest reply on Apr 13, 2007 5:33 PM by cptnkirk

    core:managed-persistence-context question

    Jon Hinckley Newbie

      I'm still trying to make sure I understand the relationship if any between the <core:managed-persistence-context /> entry in components.xml and the persistence.xml persistence-unit declaration. Given the follow from components.xml:

      (2)<core:managed-persistence-context name="entityManager" auto-create="true"
      (1)persistence-unit-jndi-name="java:/seamspaceEnitityManagerFactory" />

      and the following from persistence.xml:

      <persistence-unit name = "seamspaceDatabase">
       <property name = "jboss.entity.manager.factory.jndi.name"
      (1) value="java:/seamspaceEntityManagerFactory" />

      (1) What is this doing for me? Where would I use / take advantage of this in my code?
      (2) Where and how if anywhere do I use the entityManager specified here.
      I've seen the following:
      @In EntityManager entityManager
      Are these related?



        • 1. Re: core:managed-persistence-context question

          The is the typical @In vs @PersistenceContext question. The answer is summed up nicely in this thread.


          Basically to answer your questions:

          1. What the <core:...> is doing for you is configuring a Seam managed persistence context. You take advantage of this by using the Seam managed context instead of the EJB3 managed context.

          2. How do I do that? Use the @In annotation. The Seam managed context is a Seam component exposed via Seam's bijection mechanism so use the @In annotation to get it.

          3. So how are they different? See Christian's answer in the link above, or read my answer here. First, the following link has a good description of Seam and ORM. http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/persistence.html Use the link to familiarize yourself with the benefits of the EJB3 extended PersistenceContext. The difference between the Seam PC and the EJB3 PC is that Seam provides a couple of features that EJB3 doesn't, otherwise in terms of APIs they're the same.

          1. The lifecycle of the EJB3 PC is bound to a Stateful Session Bean, and is only shared between components participating in the same transaction. The Seam PC has conversation scope and can be injected into any component participating in that conversation regardless of its transaction context.

          2. Seam PC has better clustering and caching abilities. See the Seam doc link above for reasons why.

          3. Seam PC is managed by Seam not EJB3, thus it can be used within non EJB3 Seam components. So you can still benefit from a standard JPA interface while allowing Seam to manage the PC and transactions for you, all outside of EJB3.