glassfish
  1. glassfish
  2. GLASSFISH-20880

Glassfish 4.0 erroneously uses jdbc/__default JNDI binding for JDBC resource-refs

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 4.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      The Application Deployment Guide claims:

      If a web application accesses a DataSource that is not specified in a resource-ref in glassfish-web.xml, or there is no glassfish-web.xml file, the resource-ref-name defined in web.xml is used. A warning message is logged, recording the JNDI name that was used to look up the resource.

      As I understand it, this means that

      	<resource-ref>
      		<res-ref-name>jdbc/example</res-ref-name>
      		<res-type>javax.sql.DataSource</res-type>
      		<res-auth>Container</res-auth>
      	</resource-ref>
      

      in web.xml should cause Glassfish to use the JDBC resource named jdbc/example to satisfy the resource ref. This was true in Glassfish 3.1.2.2, and I have applications whose deployments assume this behaviour. As of Glassfish 4.0, Glassfish uses jdbc/__default to satisfy the resource ref, instead, unless explicitly configured using glassfish-web.xml.

      This is awkward; the now-required deployment descriptor feels like needless repetition:

      <glassfish-web-app>
          <resource-ref>
              <res-ref-name>jdbc/example</res-ref-name>
              <jndi-name>jdbc/example</jndi-name>
          </resource-ref>
      </glassfish-web-app>
      

        Activity

        Hide
        ojacobson added a comment -

        I've put together a more complete repro case: https://github.com/ojacobson/glassfish4-jndi-jdbc-bug

        Show
        ojacobson added a comment - I've put together a more complete repro case: https://github.com/ojacobson/glassfish4-jndi-jdbc-bug
        Hide
        ojacobson added a comment -

        After discussing this with David M. Lloyd from JBoss, to compare implementation behaviours and to pick his brain about the spec, I'd like to amend the title and remove "erroneously". The Java EE spec permits Glassfish 4's interpretation, and it's not an unreasonable interpretation; that it's not the same as Glassfish 3's does not mean it's wrong.

        It's probably worth updating the application deployment guide to document the new behaviour, if this is an intended change; I can modify my deployment process to defend apps from vague parts of the EE spec such as this. Also of note: the lookup-name child of a resource-ref can be used to specify a Glassfish global JNDI name to use when satisfying the resource ref; this probably deserves calling out in the Glassfish docs, as it may not be obvious enough.

        Show
        ojacobson added a comment - After discussing this with David M. Lloyd from JBoss, to compare implementation behaviours and to pick his brain about the spec, I'd like to amend the title and remove "erroneously". The Java EE spec permits Glassfish 4's interpretation, and it's not an unreasonable interpretation; that it's not the same as Glassfish 3's does not mean it's wrong. It's probably worth updating the application deployment guide to document the new behaviour, if this is an intended change; I can modify my deployment process to defend apps from vague parts of the EE spec such as this. Also of note: the lookup-name child of a resource-ref can be used to specify a Glassfish global JNDI name to use when satisfying the resource ref; this probably deserves calling out in the Glassfish docs, as it may not be obvious enough.

          People

          • Assignee:
            michael.y.chen
            Reporter:
            ojacobson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: