OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [class oracle.jdbc.driver.OracleConnection]

解决方案 »

  1.   

    Oracle驱动的版本问题,根据你自己的oracle及driver的版本改写org.springframework.jdbc.support.lob.OracleLobHandler
      

  2.   


    Oracle的jdbc必须是ojdbc14.jar,Oracle的版本必须是9.0.2及以上。
      

  3.   

    我换为ojdbc14.jar,还是不行.
    环境:tomcat5.0.28,dbcp, oracle9.2.0.3.0,hibernate3.0.5,spring1.2.5
      

  4.   

    我看到 oracle9.2.0.3.0的ojdbc.jar里既有oracle.jdbc.OracleConnection,也有oracle.jdbc.driver.OracleConnection,怎么回事?
      

  5.   

    Comment by Juergen Hoeller [02/Oct/05 04:41 PM] 
    This is likely to be caused by a class loader issue: that is, the Oracle JDBC driver classes being available from multiple class loaders.Spring's OracleLobHandler used a locally loaded OracleConnection class to check whether the given Connection handle is actually an Oracle JDBC connection. That might fail if the locally loaded OracleConnection class is not the same as the one used at the server level.Consequently, we've relaxed that check to accept any kind of Connection handle. If a ClassCastException arises within the Oracle driver's BLOB/CLOB handling (a sign of a non-OracleConnection passed in), we throw an expressive exception that indicates to specify a correct NativeJdbcExtractor.Essentially, it's a post-invocation check rather than a pre-invocation check now, which should avoid any potential class loader issues.This change should be available in Monday night's nightly Spring snapshot. Please give it a try and let us know whether it works for you!Juergen 
    上面是从网上找的,没怎么看明白.
      

  6.   

    看了看相关的源码,
    这是CommonsDbcpNativeJdbcExtractor的实现:
    protected Connection doGetNativeConnection(Connection con) throws SQLException {
    if (con instanceof DelegatingConnection) {
    Connection nativeCon = ((DelegatingConnection) con).getInnermostDelegate();
    // For some reason, the innermost delegate can be <code>null</code>: not for a
    // Statement's Connection but for the Connection handle returned by the pool.
    // We'll fall back to the MetaData's Connection in this case, which is
    // a native unwrapped Connection with Commons DBCP 1.1 and 1.2.
    return (nativeCon != null ? nativeCon : con.getMetaData().getConnection());
    }
    return con;
    }这是C3P0NativeJdbcExtractor的实现:
    protected Connection doGetNativeConnection(Connection con) throws SQLException {
    if (con instanceof C3P0ProxyConnection) {
    C3P0ProxyConnection cpCon = (C3P0ProxyConnection) con;
    try {
    return (Connection) cpCon.rawConnectionOperation(
    this.getRawConnectionMethod, null, new Object[] {C3P0ProxyConnection.RAW_CONNECTION});
    }
    catch (Exception ex) {
    throw new DataAccessResourceFailureException("Could not retrieve C3P0's raw connection", ex);
    }
    }
    return con;
    }我想,自己实现一个NativeJdbcExtractor,根据你的oracle driver来实现doGetNativeConnection方法,返回一个oracle.jdbc.driver.OracleConnection应该就可以了。
      

  7.   

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    <property name="lobHandler">
    <ref local="oracleLobHandler" />
    </property>
    <property name="mappingResources">
    <list>...</list>
    </property>
    <property name="hibernateProperties">...</property>
    </bean>
    <bean id="oracleLobHandler"
    class="org.springframework.jdbc.support.lob.OracleLobHandler"
    lazy-init="true">
    <property name="nativeJdbcExtractor">
    <ref local="nativeJdbcExtractor" />
    </property>
    </bean>
    <!--使用dbcp连接池时启用-->
    <bean id="nativeJdbcExtractor"
    class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
    lazy-init="true" /> 
    然后JavaBean里面是blob的字段要定义成 byte[] 然后就ok了.驱动当然最好推荐用oracle10的驱动.