6 Replies Latest reply on Feb 22, 2013 12:54 PM by piwaf

    JNDI look up binding

    camiloahm

      Hello,

       

      How can I create aliases of the JNDI Names for a datasource?

       

      I created this datasource

       

                      <datasource jta="false" jndi-name="java:/prueba2" pool-name="dspruebas" enabled="true" use-ccm="true">

                          <connection-url>jdbc:sqlserver://dev-camiloh:1433;databaseName=pruebas</connection-url>

                          <driver>MICROSOFTSQLSERVER</driver>

                          <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>

                          <security>

                              <user-name>ww</user-name>

                              <password>ww</password>

                          </security>

                          <validation>

                              <validate-on-match>false</validate-on-match>

                              <background-validation>false</background-validation>

                          </validation>

                          <statement>

                              <share-prepared-statements>false</share-prepared-statements>

                          </statement>

                      </datasource>

       

       

      I have an application with this persistence.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence version="2.0" 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_2_0.xsd">

          <persistence-unit name="Prueba2UN" transaction-type="JTA">

              <jta-data-source>prueba2</jta-data-source>

              <properties/>

          </persistence-unit>

      </persistence>

       

       

      I tried to use the next subsystem

       

      <subsystem xmlns="urn:jboss:domain:naming:1.1">

          <bindings>

              <lookup name="prueba2" lookup="java:/prueba2"/>

          </bindings>

      </subsystem>

       

      And I got an exception during service startup DuplicateServiceException, I know that I can use resource-ref in a jboss-ejb3.xml and it works,but what I want is to make a global alias for the jndi of the datasource

       

      Thanks.

       


       

       

       

       

       

       

       


        • 1. Re: JNDI look up binding
          bcantrick

          One thing that catches my eye is: <datasource jta="false"    <-- Maybe that needs to be jta="true" ?

           

           

          Another thing you can try, I don't know if this will work or not...

           

          Make a WEB-INF/jboss-web.xml file in your .WAR file. Inside it put:

           

          <jboss-web>

                  <resource-ref>

                          <res-ref-name>prueba2-copia-por-jta</res-ref-name>      <!-- Fake name. -->

                          <jndi-name>java:/prueba2<jndi-name>                          <!-- Real JNDI name. -->

                          <res-type>javax.sql.DataSource</res-type>

                  </resource-ref>

          </jboss-web>

           

          And then in persistence.xml:

           

          <jta-data-source>prueba2-copia-por-jta</jta-data-source>

           

           

          I dunno if any of that will help or not. But you can try it.

          • 2. Re: JNDI look up binding
            camiloahm

            Hi Ben

             

            Thanks for the answer

             

            It works with jboss-ejb3.xml and with jboss-web.xml but that's what I want to avoid because I have many resources in my projects.

            • 3. Re: JNDI look up binding
              bcantrick

              Whoops, sorry! I should have read your original post more carefully.

              • 4. Re: JNDI look up binding
                jaikiran

                Camilo Andrés Hernández wrote:

                 

                And I got an exception during service startup DuplicateServiceException,


                Please post the entire exception stacktrace. What version of JBoss AS7 is this?

                • 5. Re: JNDI look up binding
                  piwaf

                  Did you ever get this to work?  I am trying to do the same, a global alias defined in the profile rather then in the individual deployments.

                  • 6. Re: JNDI look up binding
                    piwaf

                    A little more research and I answered my own question, yes it's possible and here's how.  It's basically what you tried but I believe your lack of "java:" is what messed you up in the name element of the lookup.

                     

                    <subsystem xmlns="urn:jboss:domain:naming:1.1" >

                      <bindings>

                        <lookup name="java:global/c" lookup="java:global/b" />

                    </bindings>

                    </subsystem>

                     

                    From https://docs.jboss.org/author/display/AS71/JNDI+Reference