Oracle Lob Support With Hibernate And Spring

关于HIBERNATE+SPRING操作ORACLE的BLOG(CLOB)数据的问题
From http://leng.iteye.com/blog/237651

OracleHibernateSpringBlobJDBC

我们的系统采用的是HIBERNATE+SPRING进行数据的操作,开始一直采用HIBERNATE进行数据库的直连,用SPRING对ORACLE对BLOG字段进行处理,这两天打算采用PROXOOL对数据源进行管理,访问数据都没有问题,可对数据进行SAVEORUPDATE的时候报错如下:

occour a unkonw error from actionlocation OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [oracle.jdbc.internal.OracleConnection$$EnhancerByProxool$$10e3032b]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: oracle.jdbc.internal.OracleConnection$$EnhancerByProxool$$10e3032b

想着应该是nativejdbcextractor的原因,在网上找了不少资料,终于搞明白了,原来在用SPRING配置处理BLOB(CLOB)字段时,不同版本的数据库,其NATIVEJDBCEXTRACTOR是不同的,我们用的是10G的数据,但原来的配置是

<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" /> 
    <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true"> 
        <property name="nativeJdbcExtractor"> 
            <ref bean="nativeJdbcExtractor" /> 
        </property> 
    </bean>

这种配置的方法是针对9i的,因为Oracle9i处理Clob的方式和别的数据库很不一样,甚至与Oracle10g都不兼容。
所以,正确的配置应该是

<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>

轻松搞定,网上这方面的资料较少,真得在实际工作中慢慢积累经验呀:)

至于SPRING操作BLOG(CLOB)的方法,网上讲的较多,就不多说了,呵呵。加载PROXOOL与是相对比较容易的
hibernate.config.xml配置段如下:

<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> 
<property name="hibernate.proxool.pool_alias">dbpool</property> 
<property name="hibernate.proxool.xml">proxool.xml</property> 
<property name="hibernate.connection.release_mode">auto</property> 
<property name="hibernate.cglib.use_reflection_optimizer">true</property> 
<property name="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>
<property name="hibernate.show_sql">false</property> 
<property name="hibernate.connection.autocommit">true</property>

proxool.xml如下:

<?xml version="1.0" encoding="utf-8"?> 
<!-- the proxool configuration can be embedded within your own application's. 
Anything outside the "proxool" tag is ignored. --> 
<something-else-entirely> 
  <proxool> 
    <alias>dbpool</alias> 
    <driver-url>jdbc:oracle:thin:@dbip:1521:orcl</driver-url> 
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> 
    <driver-properties> 
      <property name="user" value="user"/> 
      <property name="password" value="pass"/> 
    </driver-properties> 
    <house-keeping-sleep-time>90000</house-keeping-sleep-time> 
    <prototype-count>5</prototype-count> 
    <maximum-connection-count>100</maximum-connection-count> 
    <minimum-connection-count>10</minimum-connection-count> 
  </proxool> 
</something-else-entirely>