CLOB乱码.docx

上传人:b****8 文档编号:9229754 上传时间:2023-02-03 格式:DOCX 页数:20 大小:86.49KB
下载 相关 举报
CLOB乱码.docx_第1页
第1页 / 共20页
CLOB乱码.docx_第2页
第2页 / 共20页
CLOB乱码.docx_第3页
第3页 / 共20页
CLOB乱码.docx_第4页
第4页 / 共20页
CLOB乱码.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

CLOB乱码.docx

《CLOB乱码.docx》由会员分享,可在线阅读,更多相关《CLOB乱码.docx(20页珍藏版)》请在冰豆网上搜索。

CLOB乱码.docx

CLOB乱码

分享到

Hibernate+Spring彻底搞定Clob、Blob的存取

2007-11-1617:

28:

54

标签:

SpringHibernate休闲BlobClob

版权声明:

原创作品,如需转载,请与作者联系。

否则将追究法律责任。

Hibernate+Spring彻底搞定Clob、Blob的存取

 

 

摘要:

本文通过一个实例讲述如何通过Spring2+Hibernate3来快捷操作数据库中的Lob字段。

环境:

Oracle10g、Srping2、Hibernate3、JUint4

 

说明:

由于时间紧迫,没有详细写出思路。

运行一下例子就明白了。

 

 

一、创建实体并添加Xdoclet的Hibernate标签

 

/**

 *@authorleizhimin

 *@hibernate.mappingdefault-lazy="false"

 *@hibernate.metaattribute="class-description"value="工作日志"

 *@hibernate.classtable="rc_gzrz"

 */

publicclassWorkNote{

   privateLongid;                   //标识

   privateDateworkDate;            //日期

   privateStringweather;            //天气

   privateStringcontent;            //日志内容(Clob)

   privateStringstate;              //日志状态

   privateLongorgId;                //机构id

   privateLonguserId;               //用户id

   privateDatecreateDate;           //创建日期

   privatebyte[]image;              //图片

 

   publicstaticfinalStringWORKNOTE_BLANK="00";        //未填写

   publicstaticfinalStringWORKNOTE_FULL="11";         //已填写

 

   /**

    *@hibernate.idgenerator-class="sequence"column="BS"

    *@hibernate.metaattribute="field-description"value="标识"

    *@hibernate.generator-paramname="sequence"value="SEQ_GW"

    */

   publicLonggetId(){

       returnid;

   }

 

   publicvoidsetId(Longid){

       this.id=id;

   }

 

   /**

    *@hibernate.propertycolumn="workDate"not-null="false"type="timestamp"

    *@hibernate.metaattribute="field-description"value="工作日期"

    */

 

   publicDategetWorkDate(){

       returnworkDate;

   }

 

   publicvoidsetWorkDate(DateworkDate){

       this.workDate=workDate;

   }

 

   /**

    *@hibernate.propertycolumn="weather"not-null="false"length="24"

    *@hibernate.metaattribute="field-description"value="天气"

    */

   publicStringgetWeather(){

       returnweather;

   }

 

   publicvoidsetWeather(Stringweather){

       this.weather=weather;

   }

 

   /**

    *@hibernate.propertycolumn="content"not-null="false"type="text"

    *@hibernate.metaattribute="field-description"value="内容"

    */

   publicStringgetContent(){

       returncontent;

   }

 

   publicvoidsetContent(Stringcontent){

       this.content=content;

   }

 

   /**

    *@hibernate.propertycolumn="state"not-null="false"length="2"

    *@hibernate.metaattribute="field-description"value="状态"

    */

   publicStringgetState(){

       returnstate;

   }

 

   publicvoidsetState(Stringstate){

       this.state=state;

   }

 

   /**

    *@hibernate.propertycolumn="orgId"type="long"

    *@hibernate.metaattribute="field-description"value="机构id"

    */

   publicLonggetOrgId(){

       returnorgId;

   }

 

   publicvoidsetOrgId(LongorgId){

       this.orgId=orgId;

   }

 

   /**

    *@hibernate.propertycolumn="userId"type="long"

    *@hibernate.metaattribute="field-description"value="用户id"

    */

   publicLonggetUserId(){

       returnuserId;

   }

 

   publicvoidsetUserId(LonguserId){

       this.userId=userId;

   }

 

   /**

    *@hibernate.propertycolumn="createDate"not-null="false"type="timestamp"

    *@hibernate.metaattribute="field-description"value="创建日期"

    */

   publicDategetCreateDate(){

       returncreateDate;

   }

 

   publicvoidsetCreateDate(DatecreateDate){

       this.createDate=createDate;

   }

 

   /**

    *@hibernate.propertycolumn="image"type="blob"not-null="false"

    *@hibernate.metaattribute="field-description"value="图片"

    */

   publicbyte[]getImage(){

       returnimage;

   }

 

   publicvoidsetImage(byte[]image){

       this.image=image;

   }

}

 

二、通过XDoclet生成Mapping,并修正lob映射的类型为Spring提供的类型

 

xmlversion="1.0"encoding="gb2312"?

>

 

DOCTYPEhibernate-mappingPUBLIC

   "-//Hibernate/HibernateMappingDTD3.0//EN"

   "[url]

 

       default-lazy="false"

>

   

       name="com.topsoft.oa.routine.domain.office.entity.WorkNote"

       table="rc_gzrz"

   >

       工作日志

 

       

           name="id"

           column="BS"

           type="java.lang.Long"

       >

           标识

           

               SEQ_GW

             

-- 

                 ToaddnonXDocletgeneratorparameters,createafilenamed

                 hibernate-generator-params-WorkNote.xml

                 containingtheadditionalparametersandplaceitinyourmergedir.

             -->

           

       

 

       

           name="workDate"

           type="timestamp"

           update="true"

           insert="true"

           column="workDate"

           not-null="false"

       >

           工作日期

       

 

       

           name="weather"

           type="java.lang.String"

           update="true"

           insert="true"

           column="weather"

           length="24"

           not-null="false"

       >

           天气

       

 

       

           name="content"

           type="org.springframework.orm.hibernate3.support.ClobStringType"

           update="true"

           insert="true"

           column="content"

           not-null="false"

       >

           内容

       

 

       

           name="state"

           type="java.lang.String"

           update="true"

           insert="true"

           column="state"

           length="2"

           not-null="false"

       >

           状态

       

 

       

           name="orgId"

           type="long"

           update="true"

           insert="true"

           column="orgId"

       >

           机构id

       

 

       

           name="userId"

           type="long"

           update="true"

           insert="true"

           column="userId"

       >

           用户id

       

 

       

           name="createDate"

           type="timestamp"

           update="true"

           insert="true"

           column="createDate"

           not-null="false"

       >

           创建日期

       

 

       

           name="image"

           type="org.springframework.orm.hibernate3.support.BlobByteArrayType"

           update="true"

           insert="true"

           column="image"

           not-null="false"

       >

           图片

       

 

       

--

           ToaddnonXDocletpropertymappings,createafilenamed

               hibernate-properties-WorkNote.xml

           containingtheadditionalpropertiesandplaceitinyourmergedir.

       -->

 

   

 

 

 

 

三、通过Mapping用XDoclet生成数据库(Oracle)脚本,并建表

 

   droptablerc_gzrzcascadeconstraints;

 

 

   createtablerc_gzrz(

       BSnumber(19,0)notnull,

       workDatetimestamp,

       weathervarchar2(24char),

       contentclob,

       statevarchar2(2char),

       orgIdnumber(19,0),

       userIdnumber(19,0),

       createDatetimestamp,

       imageblob,

       primarykey(BS)

   );

 

   commentontablerc_gzrzis

       '工作日志';

 

   commentoncolumnrc_gzrz.BSis

       '标识';

 

   commentoncolumnrc_gzrz.workDateis

       '工作日期';

 

   commentoncolumnrc_gzrz.weatheris

       '天气';

 

   commentoncolumnrc_gzrz.contentis

       '内容';

 

   commentoncolumnrc_gzrz.stateis

       '状态';

 

   commentoncolumnrc_gzrz.orgIdis

       '机构id';

 

   commentoncolumnrc_gzrz.userIdis

       '用户id';

 

   commentoncolumnrc_gzrz.createDateis

       '创建日期';

 

   commentoncolumnrc_gzrz.imageis

       '图片';

 

 

 

四、创建DAO层

 

 

/**

 *CreatedbyIntelliJIDEA.

 *User:

leizhimin

 *Date:

2007-11-16

 *Time:

10:

55:

50

 *TochangethistemplateuseFile|Settings|FileTemplates.

 */

publicinterfaceWorkNoteDAOextendsCommonDAO{

   /**

    *根据日期查询工作日志

    *

    *@paramworkDate工作日期

    *@paramuserId  用户id

    *@paramorgId   机构id

    *@paramsp      分页对象

    *@returnList

    */

   publicListfindWorkNoteByDate(DateworkDate,LonguserId,LongorgId,SplitPagesp);

 

   /**

    *根据状态查询工作日志

    *

    *@paramstate    日志状态

    *@paramuserId   用户id

    *@paramorgId    机构id

    *@paramsp       分页对象

    *@returnList

    */

   publicListfindWorkNoteByState(Stringstate,LonguserId,LongorgId,SplitPagesp);

}

 

 

 

/**

 *CreatedbyIntelliJIDEA.

 *User:

leizhimin

 *Date:

2007-11-16

 *Time:

10:

56:

00

 *TochangethistemplateuseFile|Settings|FileTemplates.

 */

publicclassWorkNoteDAOImplextendsCommonDAOImplimplementsWorkNoteDAO{

   publicListfindWorkNoteByDate(DateworkDate,LonguserId,LongorgId,SplitPagesp){

       returnnull;

   }

 

   publicListfindWorkNoteByState(Stringstate,LonguserId,LongorgId,SplitPagesp){

       returnnull; 

   }

}

 

 

五、创建带JTA事务控制的业务service层

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1