使用Oracle来存储长文本始终没Mysql来的方便,Mysql不用特殊配置直接使用java.lang.String来存储Text 字段内容即可。这里可以看出Mysql的优势了吧。^-^
很久之前在网上找了些,加上自己摸索的,应该算是很简单的了。
来个总结备案。
步骤:
1。使用Clob类型来存储长文本。
2。在你的Spring的applicationContext-hibernate.xml里配置以下两个bean.
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"/>
<bean id="oracleLobHandle" class="org.springframework.jdbc.support.lob.OracleLobHandler" Lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor"/>
</property>
</bean>
3。在有clob类型sessionFactory(org.springframework.com.hibernate.LocalSessionFractoryBean)中加入
<property name="lobHandler"><ref bean="oracleLobHandle"/></property>
4。在*.hbm文件里使用长文本的字段加上对应的Java类型。
<property name="content" type="org.springframework.orm.hibernate3.support.ClobStringType" column="TRACK_CONTENT" length="100000"/>
5。上边的这个content,即JavaBean的对应的属性类型为String,不是ClobStringType。
如果只配置到这里的话,启动应用的时候会报缺少事务支持的错误,忘了具体报什么错了。
6。所以要给save,remove方法加上事务支持。
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="cnProjectTrackManager" parent="txProxyTemplate">
<property name="target">
<bean class="com.helloworld.cn.manager.project.bl.impl.ProjectTrackManagerImpl">
<property name="projectTrackDAO"><ref bean="cnProjectTrackDAO"/></property>
</bean>
</property>
</bean>
7。结束。
下边是配置所需的3个文件。
applicationContext.xml
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)