8 Replies Latest reply on Jul 27, 2010 11:59 PM by Tharindu Malimage

    JNDI and Data Source Configuration

    Tharindu Malimage Newbie

      I used following technologies,servers to develop my application,

       

      • jboss-5.1.0 AS

      • JSP/Servlet

      • EJB 3

      • Hibernate

      • MySQL 5

       

      In my application, I used JNDI name as DefaultDS. It works fine.But now I want to change my JNDI name as jdbc/uni.When I deploye application in Jboss, JNDI Naming exception has occured. I have changed several *.xml files with help of Jboss Documentation. (http://docs.jboss.org/jbossas/docs/Administration_And_Configuration_Guide/5/html_single/index.html#d0e5159).

       

      It is a great help, if someone can answer my question.

       

      Thank you.

        • 1. Re: JNDI and Data Source Configuration
          jboss q Newbie

          Could you have deployed the jdbc/uni  datasource before you used it? DefaultDS is a buit-in datasource on JBoss, if you want use aother datasource, you need to create a xxx-ds.xml file and placed it in the deploy directory.

          • 2. Re: JNDI and Data Source Configuration
            Tharindu Malimage Newbie

            I have placed datasource, called jdbc-ds.xml

             

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

            <datasources>
                <local-tx-datasource>
                    <jndi-name>jdbc/uni</jndi-name>
                    <connection-url>jdbc:mysql://localhost:3306/Malimage</connection-url>
                    <driver-class>com.mysql.jdbc.Driver</driver-class>
                    <user-name>****</user-name>
                    <password>******</password>
                       <metadata>
                       <type-mapping>mySQL</type-mapping>
                    </metadata>
                </local-tx-datasource>
            </datasources>

             

            This is my persistence.xml file

             

            <?xml version="1.0" encoding="UTF-8"?>
            <persistence version="1.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_1_0.xsd">
              <persistence-unit name="Ent-ejbPU" transaction-type="JTA">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>java:/jdbc/uni</jta-data-source>
                <exclude-unlisted-classes>false</exclude-unlisted-classes>
                <properties/>
              </persistence-unit>
            </persistence>

             

             

            What is the fault with this?

            • 3. Re: JNDI and Data Source Configuration
              jboss q Newbie

              Where the jdbc-ds.xml file was placed? BTW, you may use the jndi-view in the jmx-console to check if your datasource has beed deployed correctly.

              • 4. Re: JNDI and Data Source Configuration
                Tharindu Malimage Newbie

                I have placed jdbc-ds.xml in following folder structure.

                 

                ../jboss-5.1.0/server/default/deploy/jdbc-ds.xml

                 

                 

                I have used JMX console to veiw JNDI namespaces. But I can't figure out what it is?

                • 5. Re: JNDI and Data Source Configuration
                  R Saravana Prasad Newbie

                  Could you paste your datasource lookup java codes.

                  What jndi name string do you use to lookup datasource in your java codes.

                  • 6. Re: JNDI and Data Source Configuration
                    jboss q Newbie

                    if your datasource has beed deployed correctly, you may find the jdbc/uni item under the java: Namespace in the jndi-view of jmx-console.

                    • 7. Re: JNDI and Data Source Configuration
                      jaikiran pai Master

                      By the way, what exactly is the problem? There's no details about the problem in the thread. Can you please post the entire exception stacktrace?

                      • 8. Re: JNDI and Data Source Configuration
                        Tharindu Malimage Newbie

                        I used JNDI name as DefaultDS. It works fine.But now I  want to change my JNDI name as jdbc/uni.With contrast to previous xxx-ds.xml file, I have changed file name as uni-ds.xml and placed it under following folder structure.

                         

                        ../jboss-5.1.0/server/default/deploy/jdbc/uni-ds.xml

                         

                         

                        uni-ds.xml

                         

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

                        <datasources>
                             <local-tx-datasource>
                                 <jndi-name>jdbc/uni</jndi-name>
                                 <connection-url>jdbc:mysql://localhost:3306/Malimage</connection-url>
                                 <driver-class>com.mysql.jdbc.Driver</driver-class>
                                 <user-name>****</user-name>
                                 <password>******</password>
                                   <metadata>
                                    <type-mapping>mySQL</type-mapping>
                                 </metadata>
                            </local-tx-datasource>
                        </datasources>

                         

                         

                        persistence.xml

                         

                        <?xml version="1.0"  encoding="UTF-8"?>
                        <persistence version="1.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_1_0.xsd">
                           <persistence-unit name="Ent-ejbPU" transaction-type="JTA">
                             <provider>org.hibernate.ejb.HibernatePersistence</provider>
                             <jta-data-source>java:/jdbc/uni</jta-data-source>
                             <exclude-unlisted-classes>false</exclude-unlisted-classes>
                             <properties/>
                          </persistence-unit>
                        </persistence>

                         

                         

                         

                        When I deploy *.ear in JBoss server follwing exception has occured,  after click submit button on jsp file.

                         

                         

                         

                         

                        javax.servlet.ServletException: Error instantiating servlet class Record.AddRecord
                             org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)

                             org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

                             org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                             org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                             org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

                             org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                             org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                             org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

                             java.lang.Thread.run(Thread.java:636)

                        root cause

                        java.lang.RuntimeException: Unable to inject jndi dependency: env/Record.AddRecord/detailsFacade into property Record.AddRecord.detailsFacade: Ent not bound

                             org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:82)
                             org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:366)

                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:265)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256)

                             org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                             org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                             org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                             org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

                             org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                             org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                             org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)

                             org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                             java.lang.Thread.run(Thread.java:636)

                        root cause

                        javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: Ent not bound]

                             org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1352)
                             org.jnp.interfaces.NamingContext.lookup(NamingContext.java:817)
                             org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
                             org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)

                             org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75)
                             org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:366)

                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:265)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256)

                             org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                             org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                             org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                             org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

                             org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                             org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                             org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)

                             org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                             java.lang.Thread.run(Thread.java:636)

                        root cause

                        javax.naming.NameNotFoundException: Ent not bound

                             org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
                             org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
                             org.jnp.server.NamingServer.getObject(NamingServer.java:785)
                             org.jnp.server.NamingServer.lookup(NamingServer.java:396)

                             org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
                             org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
                             javax.naming.InitialContext.lookup(InitialContext.java:409)
                             org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1346)

                             org.jnp.interfaces.NamingContext.lookup(NamingContext.java:817)
                             org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
                             org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
                             org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75)

                             org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:366)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271)

                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:265)
                             org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256)
                             org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)

                             org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                             org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

                             org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                             org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                             org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

                             org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                             org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                             org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

                             java.lang.Thread.run(Thread.java:636)