对Oracle的大数据类型CLOB字段进行插入操作
对Oracle的大数据类型CLOB字段进行插入操作
1.spring配置:
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init="true" />
<bean id="lobHandler"
class="org.springframework.jdbc.support.lob.OracleLobHandler"
lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor" />
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="lobHandler" ref="lobHandler" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/ffcs/crm/models</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.query.substitutions">true 'Y', false 'N'</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
</props>
</property>
</bean>
2.Hibernate映射文件配置:
<property
name="content"
type="org.springframework.orm.hibernate3.support.ClobStringType"
column="CONTENT"
length="4000"
>
可用@Lob
3.PO的seter/geter:
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
4.在service层我们就可以直接将VO的content直接set进PO就OK,跟一般数据类型一样处理。
OK了!
是不是很简单?之前一直在寻找hibernate 对CLOB的支持,试过很多方法后都没有成功,后来发现spring竟然对LOB有很好的支持。
/http://blog.sina.com.cn/s/blog_727f38e60100ofrs.html转自此处
//
大家可能已经注意到 nativeJdbcExtractor和 lobHandler 都设置为 lazy-init="true",这是因为 nativeJdbcExtractor需要通过运行期的反射机制获取底层的 JDBC 对象,所以需要避免在 Spring 容器启动时就实例化这两个 Bean。
评论暂时关闭