glassfish
  1. glassfish
  2. GLASSFISH-20862

@Resource 'name/mappedName' ambiguity for DataSource created in Glassfish console.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Works as designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cdi
    • Labels:
      None
    • Environment:

      Glassfish 4.0 0n Windows XP(32-bit). Browser Chrome. Oracle 11g.

      Description

      Created Connection Pool in Glassfish admin console.
      Pool Name : OCWCD
      Resource Type : java.sql.Datasource
      Datasource Classname : oracle.jdbc.pool.OracleDataSource

      Additional Properties
      URL : jdbc:oracle:thin:@xxxxxxx:xxxx:xxxxxx
      portNumber : xxxxxxx
      databaseName : xxxxxxx
      serverName : xxxxxxx
      user : xxxxxxx
      password : xxxxxxx

      Created a JDBC Resource in Admin COnsole,
      JNDI Name : jdbc/ocwcd
      Connecition Pool : OCWCD

      In the Servlet, tried to inject resource by using,
      1. @Resource(name="jdbc/ocwcd") DataSource ds;
      2. @Resource(name="jdbc/ocwcd" mappedName="OCWCD") DataSource ds;
      3. @Resource(name="jdbc/ocwcd" mappedName="jdbc/ocwcd") DataSource ds;
      4. @Resource(mappedName="jdbc/ocwcd") DataSource ds;

      Only the 3rd and 4th option worked.
      With the 1st option received,
      ----------------------------------------
      type Exception report

      messageInternal Server Error

      descriptionThe server encountered an internal error that prevented it from fulfilling this request.

      exception

      javax.servlet.ServletException: Error instantiating servlet class come.lets.learn.servlet.ResourceByAnnotations
      root cause

      com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class come.lets.learn.servlet.ResourceByAnnotations
      root cause

      com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Res-Ref-Env-Property: jdbc/ocwcd@javax.sql.DataSource@ resolved as: jndi: OCWCD@res principal: null@mail: null
      No Runtime properties
      Database Vendor : null
      Create Tables at Deploy : false
      Delete Tables at Undeploy : false into class come.lets.learn.servlet.ResourceByAnnotations: Lookup failed for 'java:comp/env/jdbc/ocwcd' in SerialContext[myEnv=

      {java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
      root cause

      javax.naming.NamingException: Lookup failed for 'java:comp/env/jdbc/ocwcd' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

      [Root exception is javax.naming.NamingException: Lookup failed for 'OCWCD' in SerialContext[myEnv=

      {java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming, com.sun.enterprise.naming.logicalName=java:comp/env/jdbc/ocwcd}

      [Root exception is javax.naming.NameNotFoundException: OCWCD not found]]
      root cause

      javax.naming.NamingException: Lookup failed for 'OCWCD' in SerialContext[myEnv=

      {java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming, com.sun.enterprise.naming.logicalName=java:comp/env/jdbc/ocwcd}

      [Root exception is javax.naming.NameNotFoundException: OCWCD not found]
      root cause

      javax.naming.NameNotFoundException: OCWCD not found
      note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.
      ----------------------------------------

      With the 2nd option , received NullPointerException for the datasource variable.

        Activity

        Hide
        jjsnyder83 added a comment -

        I believe this is working as designed. The mappedName must be a valid JNDI name for an object in JNDI. That is why 3 and 4 are working. 2 is failing because the mappedName is used before name and so GF is using "OCWCD" as the lookup value and there is nothing in JNDI at "java:comp/env/OCWCD". 1 should work (it worked for me.)

        Show
        jjsnyder83 added a comment - I believe this is working as designed. The mappedName must be a valid JNDI name for an object in JNDI. That is why 3 and 4 are working. 2 is failing because the mappedName is used before name and so GF is using "OCWCD" as the lookup value and there is nothing in JNDI at "java:comp/env/OCWCD". 1 should work (it worked for me.)

          People

          • Assignee:
            jjsnyder83
            Reporter:
            anirudhgupta169
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: