选择显示字体大小

利用hibernate synchronizer插入oralce.clob字段

表info的映射文件info.xml为:

<?xml version=&quot;1.0&quot;?>
<!doctype hibernate-mapping public
 &quot;-//hibernate/hibernate mapping dtd//en&quot;
 &quot;http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd&quot; >

<hibernate-mapping>
 <class name=&quot;src.info&quot; table=&quot;info&quot;>
  <id
   column=&quot;info_id&quot;
   name=&quot;id&quot;
   type=&quot;integer&quot;
  >
   <generator class=&quot;vm&quot;>
                <!--param name=&quot;info&quot;>info_id</param-->
                <!--param name=&quot;info_id&quot;>next_hi_value_column</param-->
         </generator>

  </id>
  <property
   column=&quot;info_cont&quot;
   name=&quot;infocont&quot;
   not-null=&quot;false&quot;
   type=&quot;java.sql.clob&quot;
   />
  <property
   column=&quot;info_area&quot;
   length=&quot;100&quot;
   name=&quot;infoarea&quot;
   not-null=&quot;false&quot;
   type=&quot;string&quot;
   />
  <property
   column=&quot;info_date&quot;
   length=&quot;7&quot;
   name=&quot;infodate&quot;
   not-null=&quot;false&quot;
   type=&quot;date&quot;
   />
 </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(&quot; &quot;) );
        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   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons