Error casting T4CConnection to OracleConnection

。_饼干妹妹 提交于 2019-12-22 08:46:26

问题


Spring application using JNDI lookup to get datasource as following:

   @Bean(name = "dataSource1", destroyMethod = StringUtils.EMPTY)
    public DataSource dataSource() {
        final JndiDataSourceLookup lookup = new JndiDataSourceLookup();
        lookup.setResourceRef(true);

        return lookup.getDataSource(this.environment.getProperty(Constants.DB_JNDI_NAME_ES));
    }

and getting a connection from the datasource as follows :

@Autowired
@Qualifier("dataSource1")
private DataSource ds;



 Connection conn = null;
 conn = this.ds.getConnection();

But when i pass that connection to StructDescriptor it throws classCastException as follows:

StructDescriptor desc1 = StructDescriptor.createDescriptor("MSAF_DBA.AMOUNT_DUE_OBJ",conn);

java.lang.ClassCastException: weblogic.jdbc.wrapper.PoolConnection_oracle_jdbc_driver_T4CConnection cannot be cast to oracle.jdbc.OracleConnection
    at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:101)
    at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:72)
    at com.ceiwc.es.policyholder.dao.PolicyHolderDaoImpl.getAmountDue(PolicyHolderDaoImpl.java:290)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)

My understanding is the getConnection() returns a T4CConnection where as OracleConnection is required. Tried couple of ways to get the oracleConnection but cant seem to get it. Any help would be appreciated.


回答1:


I believe this has to do with the contents of your war/ear file. Do not package in the Oracle driver .jar file.

Specifically, if you have ojdbc6.jar in your war file (or the equivalent) it will cause conflicts. It is fine to use that jar for compilation but you won't want it in your classpath as it is already in the Weblogic classpath by default.

See these links for similar info: here and here



来源:https://stackoverflow.com/questions/27281407/error-casting-t4cconnection-to-oracleconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!