1 Reply Latest reply on May 14, 2009 3:44 PM by Peter Johnson

    WrappedDataSource class cast exception in jboss 5.1

    John Ament Master

      So I'm using JBoss 5.1 CR1 and I've got a small bit of code that looks like this:

      Object ds = ctx.lookup("HRDS");
       log.error("The class type is: "+ds.getClass().getCanonicalName());
       DataSource hr = (DataSource)ctx.lookup("HRDS");

      when the log statement is written, I see org.jboss.resource.adapter.jdbc.WrapperDataSource which is what I expect, so it can in fact find the datasource.

      However, when I try to cast it to javax.sql.DataSource

      Generic exception: ^%^ >>>stack of 1.cause::java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource

      I thought wrapped data source extended DataSource? Also, my Hibernate connections can work with it fine. hmmm

        • 1. Re: WrappedDataSource class cast exception in jboss 5.1
          Peter Johnson Master

          What JAR files are you including in your app? (Also, what type of apps? WAR? EAR?) This type of class cast exception often happens when a class provided by JBoss AS (DataSource in this case) is also located within a JAR packaged with the app.

          If that doesn't help, you could add the "-verbose:class" JVM option to JAVA_OPTS in run.bat or run.comf. This option causes the JVM to print the location of the JAR file for each class loaded. This can help pinpoint when classes are loaded from unexpected JARs.