Spring大楷段处理

Spring大字段处理
1.applicationContext-hibernate.xml

<!-- 大对象处理器 -->
<bean id="lobHandler" lazy-init="true"
class="org.springframework.jdbc.support.lob.DefaultLobHandler" />

<!--Hibernate SessionFatory-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 大对象处理器 -->
<property name="lobHandler" ref="lobHandler" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<!--
<prop
key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
-->
<!-- <prop key="hibernate.cache.use_query_cache">true</prop>-->
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/philwong/www/platform/demo/bean</value>
</list>
</property>
</bean>

2.Userinfo.hbm.xml

<property name="useraddress" type="org.springframework.orm.hibernate3.support.ClobStringType" lazy="true">
<column name="USERADDRESS">
<comment>地址</comment>
</column>
</property>

3.Userinfo.java

private String useraddress;

public String getUseraddress() {
return useraddress;
}

public void setUseraddress(String useraddress) {
this.useraddress = useraddress;
}

总结:
1.操作blob,java类的成员变量类型设置为byte[],映射文件设置为:org.springframework.orm.hibernate3.support.BlobByteArrayType
2.操作clob,java类的成员变量类型设置为String,映射文件设置为:org.springframework.orm.hibernate3.support.ClobStringType
使用的时候不用额外考虑,可以直接象平常使用就可以了。