IBM Support

Direct JNDI Name Usage is Deprecated in WebSphere Application Server V6.0

Troubleshooting


Problem

When creating a connection factory or datasource, a JNDI name is given by which the connection factory or data source can be looked up by a component. Though you can use a direct JNDI name, this naming method is deprecated in Version 6 of WebSphere® Application Server (WAS).

Cause

WAS assigns default values to the resource-reference data when you use the naming method for direct connection. An informational message, resembling the following, is logged to the document defaults:


J2CA0294W: Deprecated usage of direct JNDI lookup of
resource jdbc/MSSQLDS. The following default values
are used: [Resource-ref settings]

res-auth:                 1 (APPLICATION)
res-isolation-level:      0 (TRANSACTION_NONE)
res-sharing-scope:        true (SHAREABLE)
loginConfigurationName:   null
loginConfigProperties:    null
[Other attributes]

res-resolution-control:   999 (undefined)
isCMP1_x:                 false (not CMP1.x)
isJMS:                 false (not JMS)

Resolving The Problem

The J2EE programming model recommends the use of resource references and the local JNDI, an "indirect" name with the java:comp/env prefix in future releases. An "indirect" name makes any resource-reference data associated with the application available to the connection management runtime, to better manage resources based on the res-auth, res-isolation-level, res-sharing-scope, and res-resolution-control settings.

To correct this problem, please follow the steps below to modify the application to use the preferred J2EE programming model with resource references and the local JNDI java:comp/env context.

The following instruction creates a J2EE Resource Reference for an Enterprise Session Bean in IBM’s Rational Application Developer.

  1. In the Project Explorer view of the J2EE Perspective, double click on an EJB Project’s Deployment
    Descriptor (DD) to open it up in an editor.
  2. Go to the References Tab.
  3. Select the Session Bean to which you would like to add the Resource Reference.
  4. Click Add, select the radio button that says "Resource Reference" and click Next.
  5. In the Add Resource Reference dialog, specify:

    Name: (i.e. jdbc/MSSQLDS),
    Type: java.sql.DataSource, and
    Authentication: Container (typical) or Application corresponding to what is defined on
    the server DataSource configuration. Once finished it should appear to the right of the EJB
    Deployment Descriptor Editor.
  6. For the DataSource resource under "WebSphere Bindings" ensure that the correct JNDI name
    is entered (such as jdbc/MSSQLDS).



  7. Save and close the EJB Deployment Descriptor.
  8. Open your session bean in the Java Editor and add "java:comp/env/jdbc/MSSQLDS"
    to the following code for retrieving data from a database table:

    Disclaimer

    All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.




    public Collection getTest() {
    List l = new ArrayList();
    try {
    InitialContext i = new InitialContext();
    DataSource ds = (DataSource)i.lookup("java:comp/env/jdbc/MSSQLDS");
    Connection con = ds.getConnection();
    con.setReadOnly(true);
    PreparedStatement ps = con.prepareStatement("SELECT * FROM ITSO.CUSTOMER");
    ResultSet rs = ps.executeQuery();
    while(rs.next()) {
    l.add(rs.getString(1));
    }
    } catch(Exception e) {
    e.printStackTrace();
    }
    return l;
    }

[{"Product":{"code":"SSRTLW","label":"Rational Application Developer for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Integrated Test Environment","Platform":[{"code":"PF033","label":"Windows"}],"Version":"6.0;6.0.0.1;6.0.1.0;6.0.1.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSYK2S","label":"Rational Software Architect Designer"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Integrated WebSphere Test Environment","Platform":[{"code":"PF033","label":"Windows"}],"Version":"6.0;6.0.0.1;6.0.1.0;6.0.1.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
10 September 2020

UID

swg21281096