Exception:com.mchange.v2.c3p0.impl.NewProxyConnection cannot be cast to oracle.jdbc.OracleConnection
解决方法:
方法1:
//将NewProxyConnection转换为OracleConnection
conn = session.getConnection();//从C3p0获取的连接
pstm = conn.preparedStatement();
//NewProxyConnection转换为OracleConnection
C3P0NativeJdbcExtractor cp30NativeJdbcExtractor = new C3P0NativeJdbcExtractor();
OracleConnection connection = (OracleConnection) cp30NativeJdbcExtractor.getNativeConnection(pstm.getConnection());
itemFlow = oracle.sql.CLOB.createTemporary(connection, false, oracle.sql.CLOB.DURATION_SESSION);
// itemFlow = OracleUtils.createTemporaryCLOB(pstm.getConnection(),false,oracle.sql.CLOB.DURATION_CALL);
方法2:
修改配置文件,添加下面的代码:(貌似没作用???)
<bean id="nativeJdbcExtractor" lazy-init="true" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor"/>
<bean id="oracleLobHandler" lazy-init="true" class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor">
<ref bean="nativeJdbcExtractor"/>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="lobHandler" ref="oracleLobHandler"/>
...
</bean>