5 Replies Latest reply on Mar 6, 2002 7:41 PM by davidjencks

    ClassCastException getting datasource

      I found a few other posts that seem to have this problem, but none that got a n answer.


      Here's the code:

      Object o = getInitialContext().
      lookup(mapping.getParameter());
      javax.sql.DataSource source = (javax.sql.DataSource) o;

      and here is the exception:

      [ERROR,Default] java.lang.ClassCastException: org.jboss.pool.jdbc.xa.XAPoolDataSource
      [ERROR,Default] at com.getcare.servlet.DatabaseAction.perform(DatabaseAction.java:47)
      [ERROR,Default] at org.apache.struts.action.Action.execute(Action.java:369)


      This worked before I moved to the Tomcat 4.1-Jboss2.4.4 build. Is this a problem with the jboss version of the jdbc 2.0 extension conflicting with the standard definition? There is a jar ile in the Tomcat Directory that is the standard sun implementation.

        • 1. Re: ClassCastException getting datasource
          raj_skromis

          it seems your driver class does not support XADataSourse
          transaction

          • 2. Re: ClassCastException getting datasource

            No, the class cast is the other way around.
            I think it has to do withgetting the Datasource from within the Tomcat realm, as opposed to in the JBoss side of things.

            • 3. Re: ClassCastException getting datasource
              davidjencks

              Well, what happens if you take the jar with the jdbc classes out of tomcat? I don't really understand the details of the latest servlet classloader requirements, but I think they may require to try to load the class locally first. This would give an incompatible class to what you looked up in jndi.

              • 4. Re: ClassCastException getting datasource

                Here is our workaround:

                try{

                //TODO:Refactor tyhis code into the EJB Layer
                org.jboss.pool.jdbc.xa.XAPoolDataSource source
                =
                /*THis call should be an XADatasource, not the jboss specific one*/
                (org.jboss.pool.jdbc.xa.XAPoolDataSource)getInitialContext().
                lookup(datasourceName);
                connection = source.getConnection();

                for (ResultSet results = perform(connection); results.next();){
                add(new Value(results.getObject(1),results.getString(2)));
                }
                connection.commit();
                }catch(Exception e){
                e.printStackTrace();
                try{
                if (connection != null){
                connection.rollback();
                }
                }catch (SQLException rollbackE){
                System.out.println("ERROR:Could not rollback");
                }
                }finally{
                try{
                if (connection != null){
                connection.close();
                }
                }catch (SQLException e){
                e.printStackTrace();
                }
                }

                • 5. Re: ClassCastException getting datasource
                  davidjencks

                  your comment should read, /*This cast should be to the Datasource interface, not the jboss implementation*/

                  XAPoolDataSource is a DataSource implementation in front of some pooling + an XADataSource. It is not an XADataSource.