OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [class oracle.jdbc.driver.OracleConnection]
解决方案 »
- 关于select标签传多个值问题
- 急:FileTransferClient下载文件,报ControlChannelIOException超时
- webservice 问题
- 将一个连接查询转成HQL 高手请进
- 数据库的问题!请大家帮帮忙啊!
- hibernate的<set>元素的inverse属性如何理解?
- Tomcat服务器中在线用户有一些Session始终不过期,究竟是怎么回事情?
- 一个sql语句,这样写对不对
- 请教关于 JTabbedPane 和jtree 结合的问题!
- 求struts中logic的使用方法及具体例子,谢谢
- 用validator验证,怎么在客户端验证两个日期的大小
- 简单struts and html标记的区别
Oracle的jdbc必须是ojdbc14.jar,Oracle的版本必须是9.0.2及以上。
环境:tomcat5.0.28,dbcp, oracle9.2.0.3.0,hibernate3.0.5,spring1.2.5
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
上面是从网上找的,没怎么看明白.
这是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应该就可以了。
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的驱动.