12 Replies Latest reply on Nov 20, 2006 8:50 AM by weston.price

    Class Cast Exception when connecting to DataSource--JBoss4.0

    russray

      Gosh, I hope someone will answer this. I have tried for the last two days to get someone to assist me. I've research all over the net for answers and had no success on uncovering an answer.

      The issue is I have a J2EE project deploying to a JBoss server. I've got the server configured as per the install program for JBoss. Howerver, starting the server produces the below error:

      11:11:52,476 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=jdbc/pidbdev' to JNDI name 'java:jdbc/pidbdev'
      11:11:52,538 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
      org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.lang.ClassCastException: com.microsoft.jdbc.sqlserver.SQLServerDriver)
      
      ....
      
      Caused by: java.lang.ClassCastException: com.microsoft.jdbc.sqlserver.SQLServerDriver
       at org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory.getXADataSource(XAManagedConnectionFactory.java:239)
       at org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory.createManagedConnection(XAManagedConnectionFactory.java:156)
      


      I have setup the data correctly as far as I can tell:

      -ds.xml

      <datasources>
       <xa-datasource>
       <jndi-name>jdbc/pidbdev</jndi-name>
       <xa-datasource-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</xa-datasource-class>
       <xa-datasource-property name="URL">jdbc:microsoft:sqlserver://me_server:1433;databaseName=me_db</xa-datasource-property>
       <xa-datasource-property name="User">p1</xa-datasource-property>
       <xa-datasource-property name="Password">p1</xa-datasource-property>
       <min-pool-size>5</min-pool-size>
       <max-pool-size>20</max-pool-size>
       <metadata>
       <type-mapping>MS SQLSERVER2000</type-mapping>
       </metadata>
       <check-valid-connection-sql>SELECT * FROM invalidate</check-valid-connection-sql>
       </xa-datasource>
      </datasources>
      


      jboss-web.xml

      <jboss-web>
       <resource-ref>
       <res-ref-name>jdbc/pidbdev</res-ref-name>
       <jndi-name>java:/pidbdev</jndi-name>
       </resource-ref>
      </jboss-web>
      



      web.xml

      <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/pidbdev</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
      </resource-ref>
      


      When I go looking at the datasource within the jmx-console, I see this

      
      Name Type Value
      JndiName java.lang.String jdbc/pidbdev
      UseJavaContext boolean True
      JMXInvokerName javax.management.ObjectName jbosss:service=invoker,type=jrmp
      StateString java.lang.String Started
      State int 3
      ConnectionManager javax.management.ObjectName jboss.jca:service=XATxCM,name=jdbc/pidbdev
      BindName java.lang.String java:jdbc/pidbdev
      Name java.lang.String WrapperDataSourceService
      
      


      Can someone help me, please?

      Thanks for taking the time to read my post.

      Russ

        • 1. Re: Class Cast Exception when connecting to DataSource--JBos
          weston.price

          The CCE is coming when the connection is being created. What version of the SQLServer driver are you using?

          • 2. Re: Class Cast Exception when connecting to DataSource--JBos
            weston.price

            Also, what version of JBoss?

            • 3. Re: Class Cast Exception when connecting to DataSource--JBos
              russray

              I am using JBoss 4.0.5. I am using JDBC Driver for SQL Server, version number is: 2.2.0040

              I have dropped the JDBCs Driver in the <JBOSS_DIR>\server\default\lib

              I don't understand the term CCE. Can you explain?

              • 4. Re: Class Cast Exception when connecting to DataSource--JBos
                weston.price

                Looks like you might be using the wrong class for the XADatasource.

                See

                http://wiki.jboss.org/wiki/Wiki.jsp?page=SetUpAMSSQLDatasource

                XA and Local use different classes. Make sure you reference the correct *-ds.xml configuration for the version of the driver you are using.

                • 5. Re: Class Cast Exception when connecting to DataSource--JBos
                  russray

                  Weston:

                  I can't tell you how thankful I am for you help!!!!!!

                  Okay, what I did was changed the driver portion of my -ds.xml file. I also verified that I had only one -ds.xml is in the directory.

                  I removed the 3 jar files I using for the SQL Server and replaced it with the new jar file sqljdbc.jar file.


                  When I re-start the server with the correct driver name, I get the below error:

                   13:24:00,141 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=jdbc/pidbdev' to JNDI name 'java:jdbc/pidbdev'
                  13:24:00,188 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
                  org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Class not found for XADataSource com.microsoft.jdbcx.sqlserver.SQLServerDataSource; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: com.microsoft.jdbcx.sqlserver.SQLServerDataSource))
                  



                  Do I have the right version of SQL Server Driver? I was under the impression I did when I swapped out.

                  Thank you for taking the time to explain this to me.

                  Russ

                  • 6. Re: Class Cast Exception when connecting to DataSource--JBos
                    russray

                    Weston:

                    When I put the three jar files back, I get this error:

                     13:33:41,818 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=jdbc/pidbdev' to JNDI name 'java:jdbc/pidbdev'
                    13:33:41,865 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
                    org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Could not find accessor on XADataSource: ; - nested throwable: (java.lang.NoSuchMethodException: com.microsoft.jdbcx.sqlserver.SQLServerDataSource.setURL(java.lang.String)))
                    
                    



                    Any suggestions?


                    Russ

                    • 7. Re: Class Cast Exception when connecting to DataSource--JBos
                      weston.price

                      Take a look at the documentation for the XADatasource. It probably doesn't have a URL property. Chances are it uses something like database name, database host etc.

                      • 8. Re: Class Cast Exception when connecting to DataSource--JBos
                        russray

                        Weston:

                        I think JBoss has a bug. I have tried all three drivers for SQL Server (2005 and @00 from MS and Jtds) In every case, I get an error.

                        The latest info is I tried JTds and get the below error:

                        14:35:17,099 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=jdbc/pidbdev' to JNDI name 'java:jdbc/pidbdev'
                        14:35:17,146 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
                        org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Could not find accessor on XADataSource: ; - nested throwable: (java.lang.NoSuchMethodException: net.sourceforge.jtds.jdbcx.JtdsDataSource.setURL(java.lang.String)))
                        
                        



                        Russ

                        • 9. Re: Class Cast Exception when connecting to DataSource--JBos
                          weston.price

                          Not likely.

                          We have plenty of people using MSSQL. Again, did you check the documentation of the properties of the XA driver? Further, did you check your spelling. All that's happening is that the driver is telling you that it doesn't have a property URL. Again, *check the documention*. If you can prove that the XADatasource has a property called URL, then that would be an error.



                          • 10. Re: Class Cast Exception when connecting to DataSource--JBos
                            weston.price

                            Again, if you look at the Wiki page for MSSQL you will notice that in none of our sample configurations is there a URL property. Please just read the documenation and try it with:

                            xa-datasource-class>com.microsoft.jdbcx.sqlserver.SQLServerDataSource</xa-datasource-class>
                             <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
                             <xa-datasource-property name="DatabaseName">pubs</xa-datasource-property>
                             <xa-datasource-property name="SelectMethod">cursor</xa-datasource-property>
                             <xa-datasource-property name="User">sa</xa-datasource-property>
                             <xa-datasource-property name="Password">jboss</xa-datasource-property>
                            


                            Again, there is *no* URL property.

                            Reading the documentation for your driver is *strongly* encouraged.



                            • 11. Re: Class Cast Exception when connecting to DataSource--JBos
                              russray

                              Weston:

                              You are absolutely 100% right, but somehow I think you knew that--- :-)

                              The -ds.xml was incorrect. There is not such property as a URL or Port for that matter. I knew I was jumping to conclusions almost immediately as I hit the submit button.

                              Here the the new -ds.xml

                               <datasources>
                               <xa-datasource>
                               <jndi-name>jdbc/pidbdev</jndi-name>
                               <track-connection-by-tx/>
                               <isSameRM-override-value>false</isSameRM-override-value>
                               <xa-datasource-class>com.microsoft.jdbcx.sqlserver.SQLServerDataSource</xa-datasource-class>
                               <xa-datasource-property name="ServerName">me_server</xa-datasource-property>
                               <xa-datasource-property name="DatabaseName">me_db</xa-datasource-property>
                               <xa-datasource-property name="SelectMethod">cursor</xa-datasource-property>
                               <xa-datasource-property name="User">p1</xa-datasource-property>
                               <xa-datasource-property name="Password">p1</xa-datasource-property>
                               <min-pool-size>5</min-pool-size>
                               <max-pool-size>20</max-pool-size>
                               <metadata>
                               <type-mapping>MS SQLSERVER2000</type-mapping>
                               </metadata>
                               <check-valid-connection-sql>SELECT * FROM invalidate</check-valid-connection-sql>
                               </xa-datasource>
                              </datasources>
                              


                              I am getting into the database and things are working! Thank you for being so gracious!!!!!

                              I have the logging set to TRACE hoping I spot anything that would tell me I don't have the server setup properly. I am getting this WARNING. I am not sure what it means in SQL Server.

                               15:14:16,269 WARN [TransactionImpl] XAException: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=rray-wxp/1, BranchQual=, localId=1] errorCode=XAER_RMERR
                              javax.transaction.xa.XAException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]xa_commit (40000000) returns -4
                               at com.microsoft.jdbcx.sqlserver.SQLServerImplXAResource.executeXaRpc(Unknown Source)
                              


                              Would you have any thoughts on this area?


                              Thanks so much on this.......I am so new to JBoss; I would have been here alot longer had I not been coached to *READ* the documentation throughly. :-)

                              Russ


                              • 12. Re: Class Cast Exception when connecting to DataSource--JBos
                                weston.price

                                This is an XA level exception where MSSQL is telling you that the commit phase of the 2PC is failling with a -4 error code.

                                From the JTA documentation:

                                http://java.sun.com/j2ee/1.4/docs/api/index.html

                                Something looks like it is misconfigured with your SQL2000 instance, or in the driver itself. I know that there were specific things that you had to do with MSSQL2000 to enable XA to work properly. Also, there are some fairly strict requirements as to the isolation level that you must use with the JDBC driver for this to work.

                                Gonna have to read some doc I am afraid :-)