Spring 方式处理 Clob、Blob 大字段

1、在 applicationContext.xml 文件中增加如下配置:
< bean  id =  "nativeJdbcExtractor"  class = "org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"  lazy-init =  "true" > bean  >
< bean  id =  "lobHandler"  class = "org.springframework.jdbc.support.lob.OracleLobHandler"  lazy-init = "true"  >
        < property  name = "nativeJdbcExtractor"  ref = "nativeJdbcExtractor"  />
bean >

2、在  sessionFactory 中增加如下红色字的配置:
< bean  id =  "sessionFactory"  class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean"  >
        < property  name = "dataSource"  ref = "dataSource"  />
       
        <property name="lobHandler" ref="lobHandler"/>
        < property  name = "mappingResources"  >
              < list >
                    < value >  com/test/model/Announcement.hbm.xml  value >
              list >
        property >

        < property  name = "hibernateProperties"  >
              < props >
                    < prop  key = "hibernate.dialect"  > $[hibernate.dialect]   prop >
                    < prop  key = "hibernate.cache.provider_class"  > org.hibernate.cache.EhCacheProvider   prop >
                    < prop  key = "hibernate.cache.use_query_cache"  > true   prop >
                    < prop  key = "hibernate.show_sql"  > true   prop >
                    < prop  key = "hibernate.bytecode.use_reflection_optimizer"  > true   prop >
                    < prop  key = "hibernate.hbm2ddl.auto"  > $[hibernate.hbm2ddl.auto]   prop >
              props >
        property >
bean >

3、Clob字段处理, *.hbm.xml 文件配置如下:
< property  name = "content"  type = "org.springframework.orm.hibernate3.support.ClobStringType"  >
     < column  name = "CONTENT"  />
property >
4、对应的实体类中相关的字段用String 接受

5、Blob字段处理,*.hbm.xml 文件配置如下:
<  property   name  = "content"  type  = "org.springframework.orm.hibernate3.support.BlobByteArrayType"  >
     < column  name =  "CONTENT"   />
 property >
6、对应的实体类中相关的字段用 byte[] 数组接受


你可能感兴趣的:(Hibernate,Oracle,Spring)