1 Reply Latest reply on Feb 8, 2002 10:47 PM by David Jencks

    Class Cast Exception with XADatasource

    Matt Hicks Newbie

      Hi all,
      When trying to get a datasource from the connection pool, I am getting the following error.

      [16:53:43,500,EmbeddedCatalinaServiceSX] LoginServlet: init
      [16:53:43,531,Default] java.lang.ClassCastException: org.jboss.pool.jdbc.xa.XAPoolDataSource
      [16:53:43,531,Default] at org.gbc.LoginServlet.doGet(LoginServlet.java:57)
      [16:53:43,531,Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
      [16:53:43,531,Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      [16:53:43,531,Default] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      [16:53:43,531,Default] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      [16:53:43,531,Default] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      [16:53:43,531,Default] at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      [16:53:43,531,Default] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
      [16:53:43,531,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      [16:53:43,531,Default] at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      [16:53:43,546,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      [16:53:43,546,Default] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      [16:53:43,546,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      [16:53:43,546,Default] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      [16:53:43,546,Default] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      [16:53:43,546,Default] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
      [16:53:43,546,Default] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      [16:53:43,546,Default] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      [16:53:43,546,Default] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      [16:53:43,546,Default] at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
      [16:53:43,546,Default] at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)

      This is the code that I am using to get the connection:
      try {
      Context jndiContext = new InitialContext();
      DataSource ds = (DataSource)jndiContext.lookup("java:comp/env/jdbc/SQLServerPool");

      Connection con = ds.getConnection();
      } catch (Exception ex) {
      ex.printStackTrace();
      }

      with the DataSource being a javax.sql.Datasource.


      I have the following entry in my web.xml file (at the bottom):
      ...
      <!-- JDBC DataSources (java:comp/env/jdbc) -->
      <resource-ref>
      The Microsoft SQL Server Pool
      <res-ref-name>jdbc/SQLServerPool</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      ...


      and the following entry in my jboss-web.xml file:
      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-web>
      <resource-ref>
      <res-ref-name>jdbc/SQLServerPool</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/SQLServerPool</jndi-name>
      </resource-ref>
      </jboss-web>


      The connection pool appears to be working fine, as it will create connections to the database if I specify a minimum value of 5 for instance. I even have the following lines in my server.log file:
      [16:39:23,343,EmbeddedCatalinaServiceSX] addEnvEntries
      [16:39:23,343,EmbeddedCatalinaServiceSX] linkResourceEnvRefs
      [16:39:23,343,EmbeddedCatalinaServiceSX] linkResourceRefs
      [16:39:23,343,EmbeddedCatalinaServiceSX] Linking 'jdbc/SQLServerPool' to JNDI name: java:/SQLServerPool

      I would greatly appreciate it if anyone could help me with this!! Thanks

      -Matt