APPFUSE中使用CLOB类型

类别:Java 点击:0 评论:0 推荐:

更改applicationContext-hibernate.xml文件为

<beans>
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
        <property name="dataSource"><ref bean="dataSource"/></property>
        <property name="mappingResources">
            <list>
                <value>model/Role.hbm.xml</value>
                  ......
               <value>model/policy/Policycontent.hbm.xml</value>
            </list>
        </property>
       
        <property name="lobHandler"><ref bean="oracleLobHandler"/></property>
       
        <property name="hibernateProperties">
           <props> 
               <prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
               <prop key="hibernate.show_sql">true</prop>
               <prop key="hibernate.jdbc.batch_size">15</prop>
           </props>
        </property>
    </bean>

    <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
        <property name="nativeJdbcExtractor"><ref local="nativeJdbcExtractor"/></property>
    </bean>

    <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor">
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- LookupDAO: Hibernate implementation -->
    <bean id="lookupDAO" class="cn.perfectsoft.hiserviceapp.dao.hibernate.LookupDAOHibernate">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
       ......

    <!-- policyTypeDAO: Hibernate implementation -->
    <bean id="policyTypeDAO" class="cn.perfectsoft.hiserviceapp.dao.hibernate.policy.PolicyTypeDAOHibernate">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
</beans>

在hbm.xml文件中的数据库CLOB类型的映射改为spring提供的ClobStringType

    <property
        name="policycontent"
        type="org.springframework.orm.hibernate.support.ClobStringType"
        column="POLICYCONTENT"
        length="9000000"//可以在这里定义CLOB使用的大小,而oracle中最大可以使用2G的容量
    >
    </property>

不要使用hibernate提供的net.sf.hibernate.type.TextType类型

model层的java文件使用String类型即可

利用此配置,完善了AppFuse项目中针对Oracle的CLOB类型不能存储超过4000字符的限制

本文地址:http://com.8s8s.com/it/it13671.htm