hibernate 保存 oracle 10g大数据字段

Java代码  
  1. 要点如下:  
  2.   
  3.  1 、首先数据表中的clob类型对应java持久化类的String类型;而blob类型对应 byte []类型。  
  4.   
  5.  2 、定义hibernate标签时,持久化类中对应clob类型的属性的hibernate type应为text;而对应blob类型的属性的hibernate type应为binary。   
  6.   
  7.  3 、以后访问这些对应clob和blob类型的属性时,按普通属性处理,不需要特别编码。  

具体方法如下:

在hbm.xml文件里,将对应的blob的映射字段改为

Java代码  
  1. <property name= "content"  type= "binary" >  
  2.           <column name="CONTENT"  />  
  3. </property>  

如果是clob的话就改成

Java代码   收藏代码
  1. <property name= "content"  type= "text" >  
  2.           <column name="CONTENT"  />  
  3. </property>  

然后将pojo改为这样

Java代码  
  1. private   byte [] content;     //blob      
  2. //private String content; //clob   
  3. set/get....  

最后是applicationContext.xml

Xml代码  
  1. < bean   id = "nativeJdbcExtractor"   class = "org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor"   lazy-init = "true"   />       
  2. < bean   id = "lobHandler"   class = "org.springframework.jdbc.support.lob.OracleLobHandler"   lazy-init = "true" >   
  3.     < property   name = "nativeJdbcExtractor" >   
  4.         < ref   bean = "nativeJdbcExtractor" />   
  5.     </ property >   
  6. </ bean >   

 将lobHandler纳入mySessionFactory

Xml代码  
  1. < bean   id = "mySessionFactory"   class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >   
  2. ....  
  3. < property   name = "lobHandler"   ref = "lobHandler" > </ property >   
  4. ...  
  5.   
  6. > </ bean   

猜你喜欢

转载自cjjwzs.iteye.com/blog/1084714