孤灯野火
畅想的天空
posts - 2,comments - 4,trackbacks - 0
一.针对不是Oracle9i
     
1.sessionFactory中设置

<!-- 定义HibernatesessionFactory,通过该Bean,可以获得HibernateSession-->

    <bean id="sessionFactory"

       class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

      

       <property name="lobHandler">

           <ref bean="lobHandler"/>

       </property>

      

       <property name="dataSource">

           <ref bean="dataSource" />

       </property>

       <property name="hibernateProperties">

           <props>

              <prop key="hibernate.dialect">

                  org.hibernate.dialect.MySQLDialect

              </prop>

              <!--设置二级缓冲-->

              <prop key="hibernate.cache.provider_class">

                  org.hibernate.cache.EhCacheProvider

              </prop>

              <!--设置二级缓冲,打开查询缓冲-->

              <prop key="hibernate.cache.use_query_cache">true</prop>

              <!--设置显示Hibernate操作的SQL语句-->

              <prop key="hibernate.show_sql">true</prop>

           </props>

       </property>

       <property name="mappingResources">

           <list>           

              <value>

                  com/njwj/model/test.hbm.xml

              </value>

           </list>

       </property>

    </bean>

2. 

<!-- 申明处理Clob对象LobHandler -->

    <bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true" />

3.
 

hibernate实体类配置中

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.njwj.model">

    <class name="LobHandlerTest" table="lobhandlertest">

       <id name="id" column="id">

           <generator class="native"></generator>

       </id>

      

       <property name="lobhandler" column="lobhandler" type="org.springframework.orm.hibernate3.support.ClobStringType" length="200"></property>

    </class>

</hibernate-mapping>

name="lobhandler" 为实体类属性 String类型

column="lobhandler" 为数据库字段Clob类型



以上配置转Clob结束

 

*.hbm.xml配置修改如下:
   a:
操作blob,java类的成员变量类型设置为byte[],映射文件设置为:

org.springframework.orm.hibernate3.support.BlobByteArrayType
   b:操作clob,java类的成员变量类型设置为String,映射文件设置为:

org.springframework.orm.hibernate3.support.ClobStringType

使用的时候不用额外考虑,可以直接象平常使用就可以了。



    
posted on 2009-05-10 21:11 孤飞燕 阅读(1030) 评论(0)  编辑  收藏 所属分类: Spring

只有注册用户登录后才能发表评论。


网站导航: