2 Replies Latest reply on Dec 5, 2007 7:19 AM by wuhaixing

    When we need an entity-manager-factory?

    wuhaixing

      There are two different SMPC code snippet from the two seam examples:

      <persistence:managed-persistence-context name="entityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/dvdEntityManagerFactory" />



      <persistence:entity-manager-factory installed="@seamStartsPersistenceUnit@"
       name="wikiEntityManagerFactory"
       persistence-unit-name="wiki"/>
      <persistence:managed-persistence-context name="entityManager"
       auto-create="true"
       entity-manager-factory="#{wikiEntityManagerFactory}"
       persistence-unit-jndi-name="java:/entityManagerFactories/wiki">
       </persistence:managed-persistence-context>

      The second define an entity-manager-factory and use it in the managed-persistence-context.I want to know when the entity-manager-factory is needed.
      I searched in the reference,found it in the three place:
      spring
      oc4j
      special components
      but I cann't figure out it's really usage.

        • 1. Re: When we need an entity-manager-factory?
          andygibson

          Typically you don't need it, persistence contexts are always provided for you.

          However, if you wanted another persistence context, you can always get hold of the factory and create one. For example, if you had an entity, and you wanted to see what was in the database, you could use a second persistence context to view the currently persisted data.

          You could also use it to query data if you wanted to get around the fact that changes to an entity pool are flushed when you run a query. Running the query on a second entity manager would sneak around that.

          Cheers,

          Andy

          • 2. Re: When we need an entity-manager-factory?
            wuhaixing

            Thanks for your reply!