title: how to dynamically modifying unitName in @PersistenceContext
body: <p>I'm using JPA 2.1 and I have somthing like this</p>
  
  <pre><code>public class EntityManagerProducer {
      @Produces
      @PersistenceContext(unitName="first_PU")
      private EntityManager em;
      ...
  </code></pre>
  
  <p>How can I dynamically modify the <code>unitName</code> in <code>@PersistenceContext(unitName = "somer_PU")</code> to use an other entity manager? Is this possible?</p>
  
  <blockquote>
    <p>VERY IMPORTANT UPDATE</p>
  </blockquote>
  
  <p>I have a deployed application,the <code>persistence.xml</code> look like this:</p>
  
  <pre><code>&lt;persistence-unit name="db1" transaction-type="JTA"&gt;
  &lt;jta-data-source&gt;java:/jboss/datasources/PostgresDS&lt;/jta-data-source&gt;
  &lt;properties&gt;
    &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
    &lt;property name="hibernate.show_sql" value="true"/&gt;
    &lt;property name="hibernate.format_sql" value="true"/&gt;
    &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
    &lt;property name="hibernate.cache.use_second_level_cache" value="false"/&gt;
    &lt;property name="hibernate.jdbc.batch_size" value="50"/&gt;
    &lt;property name="hibernate.jdbc.batch_versioned_data" value="true"/&gt;
    &lt;property name="hibernate.order_inserts" value="true"/&gt;
    &lt;property name="hibernate.order_updates" value="true"/&gt;
    &lt;property name="hibernate.generate_statistics" value="true"/&gt;
    &lt;property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/&gt;
    &lt;property name="jboss.entity.manager.jndi.name" value="java:app/entitymanager/db1"/&gt;
    &lt;property name="jboss.entity.manager.factory.jndi.name" value="java:app/entitymanagerfactory/db1"/&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p></p>
  
  <p>At runtime, could modify the persistence.xml and add another persistence unit but I need a way to get the entitymanager that I need by passing the name of the persistence unit or something, and then using it for what I want. Then I could provide another name  of persistence unit and get a different entitymanager. Of course I would like that the transaction process still be <strong>container-managed</strong>.</p>