4 Replies Latest reply on Apr 7, 2012 11:41 PM by dvohra21

    WebLogic Cannot Find JNDI

      I am new to JDeveloper and WebLogic. I am currently using Oracle Fusion Middleware 11g R2, which includes WebLogic 10.3.5, and JDeveloper

      I installed WebLogic, and created a global data source mydbDS. I installed JDeveloper, and created a Java EE Web Application, using EJB3. Now things were going along swimmingly until I got to Entity Beans.

      Since I wanted to create the entity beans in JDeveloper from the database tables, I created a new application resource mydbDS for my database. A persistence.xml file was automatically generated with the following:
      <persistence-unit name="mydbDS">
      <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/jdbc/mydbDSDS"/>

      When I deployed the ear to the standalone Weblogic server (as setup above), everything deployed properly, but when I accessed the entity bean I created I got the following error.

      Caused by: Exception EclipseLink-7060 (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence
      Exception Description: Cannot acquire data source java:/app/jdbc/jdbc/mydbDSDS.
      Internal Exception: javax.naming.NameNotFoundException: While trying to look up /app/jdbc/jdbc/mydbDSDS in /app/ejb/E
      JB.jar#SessionEJB.; remaining name '/app/jdbc/jdbc/mydbDSDS '
      at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:429)
      at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:123)
      at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
      at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:164)
      at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:32
      at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:264)
      at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:407)
      at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:130)
      at org.eclipse.persistence.sessions.server.ExternalConnectionPool.startUp(ExternalConnectionPool.java:110)
      at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:500)
      at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:606)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:211
      at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:246)
      ... 97 more
      Caused by: javax.naming.NameNotFoundException: While trying to look up /app/jdbc/jdbc/mydbDSDS in /app/ejb/EJB.jar#Se
      ssionEJB.; remaining name '/app/jdbc/jdbc/mydbDSDS '
      at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
      at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:144)
      at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
      at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:380)
      at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyContextWrapper.java:45)
      at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:135)
      at javax.naming.InitialContext.lookup(InitialContext.java:396)
      at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:117)
      ... 108 more

      I looked at several different threads and tried each of the changes suggested ( e.g., changing the following:
      <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/jdbc/mydbDSDS"/> --> <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/mydbDS"/>
      <jta-data-source>java:/app/jdbc/jdbc/mydbDSDS</jta-data-source> --> <jta-data-source>mydbDS</jta-data-source>, etc.)

      I think I tried every combination I found on the web.

      Since no matter how I changed these values they defaulted to the values below every time I exited and restarted JDeveloper, I even dropped the resource and persistence.xml, and recreated them using a variety of different ways. But to no avail.

      When I reference the WebLogic datasource via DAOs in my code, I have no issues. It is just the entity beans.

      I need to figure out how to connect to the global datasource in my standalone WebLogic serber, bypassing the integrated server, or adjust one or more of my deployment descriptors so that the entity beans can be found.

      Pleas help, thanks.

      Edited by: user1631805 on Jan 5, 2012 7:50 AM
        • 1. Re: WebLogic Cannot Find JNDI
          René van Wijk
          What is the JNDI name of the data source?

          To what server have you targeted your data source?

          Is the data source available to the server you are deploying to, i.e., in the admin console, click environment, server, choose the appropriate server and click on the JNDI tree link.
          Here an overview is given of the available resources and their corresponding JNDI name.
          • 2. Re: WebLogic Cannot Find JNDI
            Ravi Jegga
            1. I hope you already created a datasource on Weblogic Side using weblogic admin console and create New Data Source. Create a data source preferably with this JNDI Name "jdbc/mydbDSDS". It can be anything, but standard is jdbc/whatevernameyouwant. Once data source is created, you give db details like host, port, sid, username/password. Then deploy to appropriate server(s) like using Targets screen. Once all done. Under your domain/config/jdbc, you should see a .xml file with some unique name that has all the datasource details. The jndi name tag should be like this: <jndi-name>jdbc/mydbDSDS</jndi-name>

            2. Now, edit your persistence.xml file to refer above jndi name. By default, I know, it adds that wierd name with jdbc/jdbc etc etc. But you can edit it always. Take a backup of your persistence.xml file and edit it to look like this.
              <persistence-unit name="mydbDS">
                  <property name="eclipselink.target-server" value="WebLogic_10"/>
                  <property name="eclipselink.cache.shared.default" value="false"/>
            Save it. Redeploy and see how that goes. The above file is simplified version. What it means is, just refer already deployed data source whose jndi name is "jdbc/mydbDSDS". If you really have some extra properties, you can retain them. Otherwise they are not required.

            Ravi Jegga
            • 3. Re: WebLogic Cannot Find JNDI
              Thanks for the replies.

              I ended up figuring out that there was an issue with the persistence.XML, and I'm posting what I did so that others might be able to use it if they have issues.

              What I ended up doing was the following:

              In the persistence.xml, change the following from:
              <persistence-unit name="mydbDS">
              <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/jdbc/mydbDSDS"/>

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

              and remove the line:
              <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/jdbc/mydbDSDS"/>

              Once I did that, everything deployed just fine.

              However, every time I create an entity using the database connection in JDeveloper the values reset, and I must manually correct the persistence.xml
              • 4. Re: WebLogic Cannot Find JNDI
                However, every time I create an entity using the database connection in JDeveloper the values reset, and I must manually correct the persistence.xml

                A global datasource is not required. Use the JDeveloper connection.
                For example, if the JDeveloper connection is MySQLConnection

                specify data source as follows.

                <?xml version="1.0" encoding="windows-1252" ?>
                <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" xmlns="http://java.sun.com/xml/ns/persistence">
                     <persistence-unit name="em">
                               <property name="eclipselink.target-server" value="WebLogic_10" />
                               <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/jdbc/MySQLConnectionDS" />