title: Editing Persistence.xml jta-data-source from Weblogic deployment Plan.xml
body: <p>My application is using Spring MVC 4.0.5 with Toplink Essentials JPA 2.1-60 and is deployed to a Weblogic 10.3.6.0 server.</p>
  
  <p>I'm trying to deploy 2 instances of my application in order to create a development as well as testing deployments. Both of these will use the same .war file. The two instances will have different context-roots as well as connect to different data sources.</p>
  
  <p>This will be defined in a weblogic deployment plan.</p>
  
  <p>I'm able to change the context-root without any issue. The problem is trying to change the data source.</p>
  
  <p>When I run on server directly from Eclipse, the data source is defined within weblogic.xml.
  But when I build the .war file and manually deploy the application, the data source is only defined within persistence.xml. In other words, I can change weblogic.xml all I want and it doesn't affect the which data source it connects to. I have to change it in persistence.xml for it to connect to the other data source.</p>
  
  <p>Either I can't edit persistence.xml from my deployment plan (plan.xml) or my plan.xml is just wrong.</p>
  
  <p>Is there a way to force the persistence.xml to refer to the weblogic.xml data source instead of the hard coded one? Since I know I can edit weblogic.xml using the deployment plan. If not, is there a way to edit the persistence.xml data source directly from the deployment plan (change  from jdbc/PQRS to jdbs/PQRSTest)?</p>
  
  <p>I'm not sure which files are needed to help, so I'm going to include all of them.</p>
  
  <p>Thanks for your help!</p>
  
  <p>weblogic.xml</p>
  
  <pre><code>&lt;!-- web application's server path for deployment --&gt;
  &lt;weblogic-version&gt;10.3.6&lt;/weblogic-version&gt;
  &lt;context-root&gt;pqrs&lt;/context-root&gt; 
  ...
  &lt;resource-description&gt;
      &lt;res-ref-name&gt;jdbc/PQRS&lt;/res-ref-name&gt;
      &lt;jndi-name&gt;jdbc/PQRS&lt;/jndi-name&gt;
  &lt;/resource-description&gt;
  </code></pre>
  
  <p>persistence.xml</p>
  
  <pre><code>&lt;persistence-unit name="pqrsPU" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;oracle.toplink.essentials.PersistenceProvider&lt;/provider&gt;
      &lt;non-jta-data-source&gt;jdbc/PQRS&lt;/non-jta-data-source&gt;
      ...
      &lt;properties&gt;
          &lt;property name="toplink.weaving" value="false"/&gt;
          &lt;!-- &lt;property name="toplink.logging.level" value="FINE"/&gt; --&gt;
      &lt;/properties&gt;        
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;web-app&gt;
    ...
    &lt;resource-ref&gt;
      &lt;description&gt;My DataSource Reference&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/PQRS&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
    &lt;/resource-ref&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>applicationContext.xml
      
      </p>
  
  <pre><code>&lt;!-- Processes PersistenceUnit and PersistenceContext annotations for injection of JPA resources --&gt;
  &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
  
  &lt;!-- Creates a EntityManagerFactory for use with the JPA provider --&gt;
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitName" value="pqrsPU"/&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;!-- Needs spring instrument library along with aspectjrj.jar &amp; aspectjweaver.jar libraries
      &lt;property name="loadTimeWeaver"&gt;
        &lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/&gt;
      &lt;/property&gt;
      --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>plan.xml</p>
  
  <pre><code>&lt;deployment-plan&gt;
  &lt;application-name&gt;crr&lt;/application-name&gt;
    &lt;variable-definition&gt;
      &lt;variable&gt;
        &lt;name&gt;contextRootName&lt;/name&gt;
        &lt;value&gt;/pqrsTest&lt;/value&gt;
      &lt;/variable&gt;
  
    &lt;variable&gt;
        &lt;name&gt;dataSourceName&lt;/name&gt;
        &lt;value&gt;jdbc/PQRSTest&lt;/value&gt;
      &lt;/variable&gt;
    &lt;/variable-definition&gt;
  
    &lt;module-override&gt;
      &lt;module-name&gt;pqrs.war&lt;/module-name&gt;
      &lt;module-type&gt;war&lt;/module-type&gt;
  
      &lt;module-descriptor external="false"&gt;
        &lt;root-element&gt;weblogic-web-app&lt;/root-element&gt;
        &lt;uri&gt;WEB-INF/weblogic.xml&lt;/uri&gt;
  
          &lt;variable-assignment&gt;
              &lt;name&gt;contextRootName&lt;/name&gt;
              &lt;xpath&gt;/weblogic-web-app/context-root&lt;/xpath&gt;
              &lt;operation&gt;replace&lt;/operation&gt;
          &lt;/variable-assignment&gt;
      &lt;/module-descriptor&gt;
  
      &lt;module-descriptor external="false"&gt;
          &lt;root-element&gt;persistence&lt;/root-element&gt;
          &lt;uri&gt;WEB-INF/classes/META-INF/persistence.xml&lt;/uri&gt;
          &lt;variable-assignment&gt;
              &lt;name&gt;dataSourceName&lt;/name&gt;
              &lt;xpath&gt;/persistence/persistence-unit[name="pqrsPU"]/non-jta-data-source&lt;/xpath&gt;
              &lt;operation&gt;replace&lt;/operation&gt;
          &lt;/variable-assignment&gt;
      &lt;/module-descriptor&gt;
  
    &lt;/module-override&gt;
  
    &lt;config-root&gt;/usr/local/oracle/wls103607/domains/Dpqrs/apps/test&lt;/config-root&gt;
  &lt;/deployment-plan&gt;
  </code></pre>