Spring处理Clob Blob

oracle 9i的版本处理Clob Blob很讨厌 需要先存入空的大字段 而后用流的方式对其进行selete update

spring 中使用lobHander代理的方式很好的解决了这一问 使得像处理普通字段一样处理lob字段

 

spring配置文件如下:

<!-- spring处理clob -->
 <bean id="nativeJdbcExtractor"
  class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"
  lazy-init="true" />
 <bean id="lobHandler"
  class="org.springframework.jdbc.support.lob.OracleLobHandler"
  lazy-init="true">
  <property name="nativeJdbcExtractor">
   <ref local="nativeJdbcExtractor" />
  </property>
 </bean>

 

<bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="lobHandler" ref="lobHandler" />
  <property name="configLocation">
   <value>classpath:hibernate.cfg.xml</value>
  </property>
 </bean>

 

 

hibernate hbm映射文件

对应clob字段在bean中声明为 String 

配置文件对应类型为org.springframework.orm.hibernate3.support.ClobStringType

 

 <property name="hy" type="org.springframework.orm.hibernate3.support.ClobStringType">
            <column name="HY" precision="5" />
        </property>

 

配置完成即可直接操作Clob

注意:若出现套接字问题 请更换jdbc jar包为ojdbc14.jar

       classes12.jar  classes14.jar都可能会出现问题

 

你可能感兴趣的:(spring,bean,Hibernate,jdbc,orm)