• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCastException on Oracle ArrayDescriptor

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I have a J2EE application that uses connection pooling in JBoss 4.0.2. When I try to use the Oracle ArrayDescriptor class passed into a stored procedure, I get a ClassCastException when my connection tries to access the Oracle database. The application uses ojdbc14 located in the JBoss server directory; there is no copy of this jar file in the WEB-INF/lib directory. The JBoss connection pool is configured to use the oracle.jdbc.driver.OracleDriver class. I have found many instances on Google where others have had this same problem under various environments, but no one seems to have an answer for it. The standard Java code snippet is provided by Oracle:
<p>
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(
"Oracle Dictionary Type", connection
);
ARRAY array = new ARRAY(descriptor,this.connection,stores);
</p>
<p>
com.luxotticaRetail.dme.DatabaseException: java.lang.ClassCastException
at com.luxotticaRetail.dme.user.UserUpdateProcess.execute(UserUpdateProcess.java:37)
at com.luxotticaRetail.dme.user.UserUpdateAction.executeLogic(UserUpdateAction.java:36)
at com.luxotticaRetail.struts.BaseAction.execute(BaseAction.java:58)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at com.luxotticaRetail.struts.LuxActionServlet.process(LuxActionServlet.java:38)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.luxotticaRetail.dme.SecurityContextFilter.doFilter(SecurityContextFilter.java:171)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.ClassCastException
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
at com.luxotticaRetail.dme.user.UserUpdateProcess.callUserUpdateSP(UserUpdateProcess.java:62)
at com.luxotticaRetail.dme.user.UserUpdateProcess.execute(UserUpdateProcess.java:35)
... 28 more
</p>
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

We have a strict policy on display names, which must be a real first and last name with a space between.

Please go here and fix your display name up, pronto. Thanks, pardner!
 
Saloon Keeper
Posts: 27886
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is that the JBoss connection pool subsystem is using a different classloader tree than your webapp is.

In general, I'd consider it better when referencing a class to explicitly include that class (or the jar containing it) into the actual app classpath. In other words, if you're going to use com.oracle classes in the webapp, put a copy of ojdbc14.jar in the WEB-INF/lib directory of the webapp.

This isn't without its perils. You have the potential to get royally messed up if the connection pool's ojdbc jar gets upgraded and the app's ojdbc jar isn't also upgraded.

Then again, you've already lost application portability when you use a specific DBMS vendor's classes in application code.
 
Wayne Glover
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding an update for the a resolution to this problem...

I add a cast to the connection class, changing it from java.sql.Connection to org.jboss.resource.adapter.jdbc.WrappedConnection, this being the actual class that is returned from the pool. This allowed me to gain acces to the Oracle connection that contains the implementation that I need for Oracle specific operations. Once I did that, the cast exception went away. I only did this in specific instances where my java class was using an Oracle JDBC component. Now, the code looks this:

Connection jbossConn =
((WrappedConnection) this.connection).getUnderlyingConnection();
ArrayDescriptor descriptor =
ArrayDescriptor.createDescriptor(
Oracle Dictionary Type,
jbossConn
);
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a bug. But there are two ways to overcome this issue.

1. Establish the connection using DriverManager
Connection conn = DriverManager.getConnection(url, user, password)
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(Oracle Dictionary Type, conn);

2. Using the physical connection. In this approach make sure to close the original connection and to NOT to close the physical connection.
Connection conn = this.connection; //Obtained by InitialContext.lookup(jndiDataSourceName)
Connection physicalCon = ((WrappedConnection) conn).getUnderlyingConnection();
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(Oracle Dictionary Type, physicalCon);
......
......//dont close physicalCon
conn.close();

For the second approach we need to have a reference to jboss-common-jdbc-wrapper.jar to build the package. But we dont need to bundle that jar with the final ear/war. Boz its already there in Jboss.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried the same but then also getting the same error


con = getDataSource().getConnection();
Connection connection = this.con;

Connection physicalCon = ( (WrappedConnection)connection ).getUnderlyingConnection();

OracleCallableStatement ocs = (OracleCallableStatement)physicalCon
.prepareCall( "begin sh_give_me_an_array(:x); end;" );





17:16:44,593 ERROR [STDERR] java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrappedConnection
17:16:44,593 ERROR [STDERR] at com.gts.crmw.login.dao.LoginDao.getTopMenu(LoginDao.java:451)
17:16:44,593 ERROR [STDERR] at com.gts.crmw.login.service.LoginServices.getTopMenu(LoginServices.java:266)
17:16:44,593 ERROR [STDERR] at com.gts.crmw.login.facade.LoginFacade.callService(LoginFacade.java:65)
17:16:44,593 ERROR [STDERR] at com.gts.crmw.login.action.LoginAction.getTopMenu(LoginAction.java:133)
17:16:44,593 ERROR [STDERR] at com.gts.crmw.login.action.LoginAction.executeLogic(LoginAction.java:73)
17:16:44,593 ERROR [STDERR] at com.gts.crmw.common.action.CrmwActionSupport.execute(CrmwActionSupport.java:74)
17:16:44,593 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:16:44,593 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
17:16:44,593 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
17:16:44,593 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
17:16:44,593 ERROR [STDERR] at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
17:16:44,593 ERROR [STDERR] at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
 
reply
    Bookmark Topic Watch Topic
  • New Topic