tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Wingfield <jon.wingfi...@mkodo.com>
Subject Re: JNDI, DataSource, and ClassCastException
Date Thu, 11 Dec 2003 11:57:22 GMT
It looks like a ClassLoader issue. Casting the same class loaded by two 
different CLs causes a ClassCastException. Have you got the jar 
containing org.enhydra.jdbc.pool.StandardXAPoolDataSource in more than 
one place?

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html

HTH,

Jon

Marc Dugger wrote:
> I have a situation where I am attempting to downcast a DataSource resource
> into the exact class that getClass().getName() reports the object is, but
> it's causing a ClassCastException.
> 
> --> server.xml:
> 
> <GlobalNamingResources>
>     	<Resource name="LoanAuditorDB" auth="Container"
> type="org.enhydra.jdbc.pool.StandardXAPoolDataSource"/>
>     	<ResourceParams name="LoanAuditorDB">
> ...more
> 	</ResourceParams>
> </GlobalNamingResources>
> ...more
> <Context path="/workbench"
> docBase="C:\Code\loanauditor\src\webapp\workbench"
> 
> workDir="C:\Code\loanauditor\src\webapp\workbench\WEB-INF\work"
> reloadable="true" debug="0">
>             <ResourceLink name="jdbc/loanauditor"
>                           global="LoanAuditorDB"
> 
> type="org.enhydra.jdbc.pool.StandardXAPoolDataSource"/>
>             <ResourceLink name="jta/loanauditor"
>                           global="UserTransaction"
>                           type="javax.transaction.UserTransaction"/>
>         </Context>
> 
> 
> --> web.xml
> 
> <resource-ref>
>         <description>DB Connection</description>
>         <res-ref-name>jdbc/loanauditor</res-ref-name>
>         <res-type>org.enhydra.jdbc.pool.StandardXAPoolDataSource</res-type>
>         <res-auth>Container</res-auth>
>     </resource-ref>
> 
> --> constructor from abstract class, AbstractDAO.java:
> 
> protected AbstractDAO() {
>         try {
>             Context ctx = new InitialContext();
>             Object o = ctx.lookup("java:comp/env/jdbc/loanauditor");
>             log.debug("loanauditor from JNDI: " + o.getClass().getName());
>             ds = (org.enhydra.jdbc.pool.StandardXAPoolDataSource) o;
>             ds.setJdbcTestStmt("SELECT 1");
>         } catch (NamingException ne) {
>             log.fatal(ne.getMessage(), ne);
>             throw new RuntimeException(ne);
>         }
>     }
> 
> --> logging:
> 
> 2003-12-04 05:25:39,157 [main] DEBUG
> com.socotech.loanauditor.dao.AbstractDAO - loanauditor from JNDI:
> org.enhydra.jdbc.pool.StandardXAPoolDataSource
> 
> --> stacktrace:
> 
> java.lang.ClassCastException
> 	at com.socotech.loanauditor.dao.AbstractDAO.<init>(AbstractDAO.java:31)
> 	at
> com.socotech.loanauditor.dao.TorqueDomainTypeDAO.<init>(TorqueDomainTypeDAO.
> java:34)
> 	at
> com.socotech.loanauditor.dao.TorqueDomainTypeDAO.getInstance(TorqueDomainTyp
> eDAO.java:29)
> 	at
> com.socotech.loanauditor.dao.DAOFactory.getDomainTypeDAO(DAOFactory.java:79)
> 	at
> com.socotech.loanauditor.web.listener.DomainTypeLoader.contextInitialized(Do
> mainTypeLoader.java:32)
> 	at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:
> 3271)
> 	at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:3613)
> 	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
> 	at org.apache.catalina.core.StandardHost.start(StandardHost.java:754)
> 	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
> 	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:363)
> 	at org.apache.catalina.core.StandardService.start(StandardService.java:497)
> 	at org.apache.catalina.core.StandardServer.start(StandardServer.java:2190)
> 	at org.apache.catalina.startup.Catalina.start(Catalina.java:512)
> 	at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
> 	at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
> )
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> .java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:324)
> 	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
> 
> 
> Thanks in advance for any insight.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message