oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection in JBOSS EAP 6.1

2.8k views Asked by At

I have deployed my ear in JBOSS 7.1.1 AS. For viewing the document in application we are using the BFILE. Below code is used:

Connection con = this.jdbcTemplate.getDataSource().getConnection();
con = unwrapConnection(con);

if(null != con)
{
    System.out.println("Is conncetion Closed" + con.isClosed());
    PreparedStatement ps = con.prepareStatement(sql);
    ResultSet rs = ps.executeQuery();
    while(rs.next()) {
    {
        OracleResultSet ors = rs.unwrap(OracleResultSet.class);
        bfile = ors.getBFILE(1);
        fileName = rs.getString(2);
        docFormat = rs.getString(3);
    }
    bfileMap.put("EventDocDetails", bfile);
    bfileMap.put("Format", docFormat);
    bfileMap.put("FileName", fileName);
}

private static Connection unwrapConnection(Connection connection) throws SQLException {

    System.out
        .println("Datasource is maintained by Jboss so Unwarping Jboss JDBC Connection to oracle.jdbc.OracleConnection. Driver name is "
            + connection.getMetaData().getDriverName());
    return (oracle.jdbc.OracleConnection) ((WrappedConnection) connection)
        .getUnderlyingConnection(); 
}

We are using Ojdc6.11.2.0.3 jar. In the manifest of ear I have dependencies org.jboss.ironjacamar.jdbcadapters.

This works fine for JBOSS AS 7.1.1

But same ear doesnt work in JBOSS EAP 6.1 I get below exception

oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection
19:54:51,395 ERROR [stderr] (http-/192.168.178.31:8080-5) java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection.

I am baffled as almost all the things are same.

2

There are 2 answers

0
Nick Denizhenko On

Seems like a classload issue due to two same classes exist in Jboss and in your app(WAR or EAR). In my Jboss 6.3 I'm found jboss\modules\com\oracle\ojdbc6.jar with T4CConnection.class inside which may be cause of issue. If it exist in your jboss you can try to exclude that lib in jboss-deployment-structure.xml like:

<deployment>
    <exclusions>
        <module name="com.oracle.ojdbc6"/>
    </exclusions>
</deployment>

Hope it helps.

0
user3797766 On

After a lot of head scratching i removed the JDBC drive from console of JBOSS and added a new one.It worked.