I'm working on a legacy web application running on JBoss 7.3, and getting the following exception when the code tries to execute a stored procedure
Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8
at com.mycompany.mypackage.dao.DAOUtil.executeStoredProc(DAOUtil.java:73)
at com.mycompany.mypackage.dao.PurgeDAO.getPurgeReason(PurgeDAO.java:37)
at com.mycompany.mypackage.ejb.purge.PurgeServiceBean.getPurgeReason(PurgeServiceBean.java:54)
triggered by the following code
String dataSourceSetting = "java:jboss/datasources/OracleDS"
Context oracleContext = new InitialContext();
DataSource dataSource = (DataSource) oracleContext.lookup(dataSourceSetting);
Connection connection = dataSource.getConnection();
CallableStatement statement = connection.prepareCall(storedProcedure);
Connection wrappedConnection = ((WrappedConnectionJDK8) connection).getUnderlyingConnection();
What would stop an object from being cast to the same class type?
CodePudding user response:
WrappedConnectionJDK8 is coming from 2 different classloaders. You shouldn't provide it in your application. Also you could unwrap it, that would be the proper way to get the underlying connection.
CodePudding user response:
The problem was solved with a JBoss Deployment Descriptor
jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment name="MyApp.ear">
<dependencies>
<module name="org.jboss.ironjacamar.jdbcadapters" />
<module name="com.oracle" />
</dependencies>
</deployment>
<sub-deployment name="MyApp-Web.war">
<exclusions />
<dependencies>
<module name="org.jboss.ironjacamar.jdbcadapters" />
<module name="com.oracle" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>