hibernate中clob处理

用hibernate封装oracle的clob类型操作起来很不方便,但是新的oracle10g的jdbc驱动,对此有很多改进。

环境 :wodows2000、oracle9.2、oracle10gJDBC驱动(必须)、hibernate3.1.2

oracle官方网站的clob操作方法:http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/clob10g/ClobManipulationIn10g.java.html

建表脚本:

/*==============================================================*/
/* Table: StoreFile                                             */
/*==============================================================*/
create table StoreFile  (
   uuid                 VARCHAR2(128)                   not null,
   name                 VARCHAR2(200),
   text                 CLOB,
   constraint PK_STOREFILE primary key (uuid)
);

hibernate.cfg.xml:(注意多了个SetBigStringTryClob设置,其它没有什么特殊的了

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.cglib.use_reflection_optimizer">true</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">java</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@10.128.4.69:1521:kf</property>
        <property name="hibernate.connection.username">java</property>
        <property name="hibernate.connection.SetBigStringTryClob">true</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.OSCacheProvider</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <mapping resource="com/study/database/hb/map/File.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

File.hbm.xml文件

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2006-3-13 17:57:00 by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping>
    <class name="com.study.database.hb.map.File" table="StoreFile" batch-size="0">
        <id name="uuid" type="string">
            <column name="UUID" length="128" />
            <generator class="uuid.hex"></generator>
        </id>
        <property name="name" type="string" lazy="false">
            <column name="NAME" length="200"/>
        </property>
        <property name="file" type="string" lazy="false">
            <column name="text" />
        </property>
    </class>
</hibernate-mapping>

File.java文件

package com.study.database.hb.map;
// Generated 2006-3-13 17:57:00 by Hibernate Tools 3.1.0.beta4

import java.sql.Clob;
/**
 * File generated by hbm2java
 */

public class File
    implements java.io.Serializable
{
  // Fields

  private String uuid;
  private String name;
  private String file;
  // Constructors

  /** default constructor */
  public File()
  {
  }
  /** full constructor */
  public File(String name,String file)
  {
    this.name=name;
    this.file=file;
  }
  // Property accessors

  public String getUuid()
  {
    return this.uuid;
  }
  public void setUuid(String uuid)
  {
    this.uuid=uuid;
  }
  public String getName()
  {
    return this.name;
  }
  public void setName(String name)
  {
    this.name=name;
  }
  public String getFile()
  {
    return this.file;
  }
  public void setFile(String file)
  {
    this.file=file;
  }
}
//比以前特殊的地方是hibernate.cfg.xml多了个SetBigStringTryClob设置。

//把clob映射成string类型,这样在多过4000个字符时也不会出错了。操作方法和普通的string类型一样。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值