- 要点如下:
- 1 、首先数据表中的clob类型对应java持久化类的String类型;而blob类型对应 byte []类型。
- 2 、定义hibernate标签时,持久化类中对应clob类型的属性的hibernate type应为text;而对应blob类型的属性的hibernate type应为binary。
- 3 、以后访问这些对应clob和blob类型的属性时,按普通属性处理,不需要特别编码。
具体方法如下:
在hbm.xml文件里,将对应的blob的映射字段改为
- <property name= "content" type= "binary" >
- <column name="CONTENT" />
- </property>
如果是clob的话就改成
- <property name= "content" type= "text" >
- <column name="CONTENT" />
- </property>
然后将pojo改为这样
- private byte [] content; //blob
- //private String content; //clob
- set/get....
最后是applicationContext.xml
- < bean id = "nativeJdbcExtractor" class = "org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" lazy-init = "true" />
- < bean id = "lobHandler" class = "org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init = "true" >
- < property name = "nativeJdbcExtractor" >
- < ref bean = "nativeJdbcExtractor" />
- </ property >
- </ bean >
将lobHandler纳入mySessionFactory
- < bean id = "mySessionFactory" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
- ....
- < property name = "lobHandler" ref = "lobHandler" > </ property >
- ...
- > </ bean