5 Replies Latest reply: Nov 18, 2012 10:08 PM by Jeets-Oracle RSS

    Changing Datasource JNDI name using plan.xml

    Jeets-Oracle
      Hello Experts,

      I have created and EJB 3.0 which is using persistence.xml

      Where titan is the datasource JNDI name configured in weblogic.

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
      http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
           <persistence-unit name="titan">
                <jta-data-source>titan</jta-data-source>
      </persistence-unit>
      </persistence>

      Now am trying to change the JNDI name for that datasource using plan.xml

      <?xml version='1.0' encoding='UTF-8'?>
      <deployment-plan xmlns="http://www.bea.com/ns/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/deployment-plan http://www.bea.com/ns/weblogic/deployment-plan/1.0/deployment-plan.xsd" global-variables="false">
           <application-name>jeets</application-name>
                <variable-definition>
                     <variable>
                          <name>datasource-jndi-name</name>
                          <value>jdbc/otherDS</value>
                     </variable>
                </variable-definition>
                
                
           <module-override>
                <module-name>jdbcPersistanceEjb</module-name>
                <module-type>ear</module-type>
           
           <module-descriptor external="false">
                     <root-element>persistence</root-element>
                     <uri>META-INF/persistence.xml</uri>
                     <variable-assignment>
                          <name>datasource-jndi-name</name>
                <xpath>/persistence/persistence-unit[name="titan2"]/jta-data-source</xpath>
                     </variable-assignment>
                </module-descriptor>
                
           </module-override>
           <config-root>D:\WeblogicDocs\JDBCPlan_Xml</config-root>
      </deployment-plan>


      And application.xml is as below:

      <?xml version="1.0" encoding="UTF-8"?>
      <application id="Application_ID" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
           <display-name>testEar</display-name>
                <module>
                <ejb>ejbjar.jar</ejb>
           </module>
      </application>

      But I still see that the datasource name as titan in deployments configuration.

      Am I missing something here or doing any thing wrong?

      Please help.

      Regards, Jetendra.
        • 1. Re: Changing Datasource JNDI name using plan.xml
          René van Wijk
          An example is given here: http://middlewaremagic.com/weblogic/?p=6168 (look at the end of the post)
          • 2. Re: Changing Datasource JNDI name using plan.xml
            Jeets-Oracle
            <variable-definition>
                           <variable>
                                <name>datasource-jndi-name</name>
                                <value>titan2</value>
                           </variable>
                      </variable-definition>
                      
                      
                 <module-override>
                      <module-name>jdbcPersistanceEjb</module-name>
                      <module-type>ear</module-type>
                      <module-descriptor external="false">
                           <root-element>persistence</root-element>
                           <uri>META-INF/persistence.xml</uri>
                           <variable-assignment>
                                <name>datasource-jndi-name</name>
                      <xpath>/persistence/persistence-unit[name="titan"]/jta-data-source</xpath>
                           </variable-assignment>
                      </module-descriptor>
                 </module-override>


            Rene infact I used the same snippet, but not able to identify, whether the new data source is picked or not.

            How to verify it?

            And going to the configuration->datasource tab it is still showing the old value.

            I have also created a new data source with the new name.

            Am I going in the right direction?
            • 3. Re: Changing Datasource JNDI name using plan.xml
              René van Wijk
              After the change in the deployment plan, did you redeploy (update) the application?

              From the post (http://middlewaremagic.com/weblogic/?p=6168):
              To check if the change has been made, navigate (using the WebLogic Console) to the defined persistence unit, i.e,
              - Click on the deployed application in the deployments table.
              - Click on the EJB module to which the persistence-unit belongs, for example ejb.jar.
              - Click on the Configuration tab and subsequently click on the corresponding persistence unit name, i.e., NewPersistenceUnit.
              - Click on the DataSources tab, and check the JTA Data Source JNDI Name attribute.

              Just to double check in the deployment plan you use: /persistence/persistence-unit[name="titan"]/jta-data-source
              Is the name of the persistence-unit titan?
              • 4. Re: Changing Datasource JNDI name using plan.xml
                Jeets-Oracle
                Yes Rene, titan is the persistant-unit name.

                I went to the location you have pointed but, new name is not reflected.

                Yes I redeployed the application. But still it did not show up. :-(
                • 5. Re: Changing Datasource JNDI name using plan.xml
                  Jeets-Oracle
                  Resolved the issue, by changing the correct xpath location.

                  Have created plan.xml by fault, which helped in correcting the exact xpath location.

                  Edited by: 807855 on Nov 18, 2012 8:08 PM