Orcale 中的CLOB字段的处理,hibernate处理clob

来源:互联网 发布:php全能运行环境 编辑:程序博客网 时间:2024/05/17 23:22

clob 在oracle中的持久化源码:

 

 public void AddClob(String AsTable, String fieldName, String id,
   String values) throws Exception {
  PrimaryKey = "ID";
  String strSQL = "SELECT " + fieldName + " FROM " + AsTable + " WHERE "
    + PrimaryKey + "='" + id + "' FOR UPDATE";
  String updateSQL = "update " + AsTable + " set " + fieldName
    + "=empty_clob() where " + PrimaryKey + "='" + id + "'  and "
    + fieldName + " is null";
  System.out.println("strSQL="+strSQL);
  System.out.println("updateSQL="+updateSQL);
  Statement ps = conn.createStatement();
  ps.executeUpdate(updateSQL);
  oracle.sql.CLOB clob = null;
  this.conn.setAutoCommit(false);
  ResultSet rs = stmt.executeQuery(strSQL);
  if (rs.next()) {
   clob = (CLOB) rs.getClob(1);
   Writer outStream = clob.getCharacterOutputStream();
   char[] c = values.toCharArray();
   outStream.write(c, 0, c.length);
   outStream.flush();
   outStream.close();
  }
  this.conn.commit();
 }

 

 

那么Orcale 中的CLOB 在hiberbate 的.hbm.xml 文件和在pojo的类映射成什么类型 ?

我的程序中pojo是String 类型 而 .hbm.xml 对应的映射为text 在数据库里为CLOB 者是在网上看到的 一种写法
而我运行程序出现 80781 [http-8080-1] WARN util.JDBCExceptionReporter  - SQL Error: 17090, SQLState: null
80781 [http-8080-1] ERROR util.JDBCExceptionReporter  - 不允许的操作: streams type cannot be used in batching
80796 [http-8080-1] ERROR def.AbstractFlushingEventListener  - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [com.viceasy.wlhk.information.bean.NewsPublicNotice]

 

 

用这个驱动ojdbc14.jar 在数据库为clobl类型 在.hbm.xml映射为text类型
pojo里为String类型 但是在 .hbm.xml 加个length="100000"
就可以了