表info的映射文件info.xml为:
<?xml version="1.0"?>
<!doctype hibernate-mapping public
"-//hibernate/hibernate mapping dtd//en"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="src.info" table="info">
<id
column="info_id"
name="id"
type="integer"
>
<generator class="vm">
<!--param name="info">info_id</param-->
<!--param name="info_id">next_hi_value_column</param-->
</generator>
</id>
<property
column="info_cont"
name="infocont"
not-null="false"
type="java.sql.clob"
/>
<property
column="info_area"
length="100"
name="infoarea"
not-null="false"
type="string"
/>
<property
column="info_date"
length="7"
name="infodate"
not-null="false"
type="date"
/>
</class>
</hibernate-mapping>
其中红色字体为要映射的oracle.clob类型。(在这里将其类型定义为java.sql.clob类型,如果定义为oracle.clob,在运行时,会抛出异.net.sf.hibernate.mappingexception: error reading resource: info.hb.net.sf.hibernate.mappingexception: error reading resource: info.hbm。我也不明白为什么,估计是找不到包,如果那位知道,请告诉我!)
下面是相应的代码片断:
// load the configuration file
_rootdao.initialize();
// create a instance of info represents a new info to be added
info newinfo = new info(new integer(id));
newinfo.setinfoarea(infoarea);
newinfo.setinfodate(calendar.getinstance().gettime());
infodao infodao = new infodao();
session s = _rootdao.createsession();
transaction tx = s.begintransaction();
// insert a empty value into info_cont first
newinfo.setinfocont(hibernate.createclob(" ") );
s.save(newinfo);
s.flush();
// lock the relative row
s.refresh(newinfo, lockmode.upgrade);
clob clob = (clob) newinfo.getinfocont();
java.io.writer pw = clob.getcharacteroutputstream();
try {
pw.write(infocont);// write the clob value into table
pw.close();
} catch(ioexception e) {
throw new hibernateexception(e);
}
tx.commit();
s.close();
不过这个方法是最笨的一个办法,更好的办法,或者说更透明的方法是通过实.net.sf.hibernate.usertype接口,来自定义处理oracle.clob类型的类。这种方法仍然在研究中:)。虽然说这个方法比较落后,但是,最起码现在可以通过hibernate插入oracle.clob字段了!
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器