Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-564

Can't get underlying PostgreSQL database connection from datasource

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.0.0.Final
    • Fix Version/s: 2016.9
    • Component/s: examples
    • Labels:
      None
    • Sprint:
      2016.9
    • Steps to Reproduce:
      Hide

      Done using datasource-subsystem example.

      1. Add dependency to ironjacamar-jdbc in pom.xml with provided scope to get WrappedConnectionJDK7 to resolve:

      <dependency>
        <groupId>org.jboss.ironjacamar</groupId>
        <artifactId>ironjacamar-jdbc</artifactId>
        <version>1.3.2.Final</version>
        <scope>provided</scope>
      </dependency>
      

      2. In MyResource.java change

      Connection conn = ds.getConnection();
      

      to

      WrappedConnectionJDK7 wc = (WrappedConnectionJDK7) ds.getConnection();
      PGConnection pgc = (PGConnection) wc.getUnderlyingConnection();
      

      to get the PostgreSQL connection.

      2. Add resources/META-INF/jboss-deployment-structure.xml with the following content:

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-deployment-structure>
          <deployment name="example-datasource-subsystem.jar">
              <dependencies>
                  <module name="org.jboss.ironjacamar.jdbcadapters" />
              </dependencies>
          </deployment>
      </jboss-deployment-structure>
      

      4. Run the example with PostgreSQL driver

      mvn wildfly-swarm:run -Dswarm.use.db=postgresql
      

      5. Open http://localhost:8080 and examine the log to see the ClassNotFoundException

      Show
      Done using datasource-subsystem example. 1. Add dependency to ironjacamar-jdbc in pom.xml with provided scope to get WrappedConnectionJDK7 to resolve: <dependency> <groupId>org.jboss.ironjacamar</groupId> <artifactId>ironjacamar-jdbc</artifactId> <version>1.3.2.Final</version> <scope>provided</scope> </dependency> 2. In MyResource.java change Connection conn = ds.getConnection(); to WrappedConnectionJDK7 wc = (WrappedConnectionJDK7) ds.getConnection(); PGConnection pgc = (PGConnection) wc.getUnderlyingConnection(); to get the PostgreSQL connection. 2. Add resources/META-INF/jboss-deployment-structure.xml with the following content: <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment name="example-datasource-subsystem.jar"> <dependencies> <module name="org.jboss.ironjacamar.jdbcadapters" /> </dependencies> </deployment> </jboss-deployment-structure> 4. Run the example with PostgreSQL driver mvn wildfly-swarm:run -Dswarm.use.db=postgresql 5. Open http://localhost:8080 and examine the log to see the ClassNotFoundException

      Description

      I need to get the underlying PostgreSQL database connection from a datasource, see "Steps to Reproduce" for how exactly I'm trying to achieve this. In Wildfly Swarm this results in a ClassNotFoundException. I have also tried this with Wildfly 10 and there it does work.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                kenfinni Ken Finnigan
                Reporter:
                w3bdevil Janne Nummi
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: