hibernate处理clob

来源:互联网 发布:日本美女直播软件 编辑:程序博客网 时间:2024/05/18 14:22

使用hibernate处理clob的时候遇到了些问题,

    <prop key="hibernate.connection.SetBigStringTryClob">true</prop>这个属性设置可以让将clob直接哪来当string使用,但是如果使用sql查询

查询出来的clob类型是 org.hibernate.lob.SerializableClob类型,这时需要序列化一下

public String clobStrValue(Object clob){
          String sResult = "";
          try {
             if (clob==null){
                return "";
             }
             org.hibernate.lob.SerializableClob clb = (org.hibernate.lob.SerializableClob) clob;
              String str = "";
                BufferedReader in = new BufferedReader(clb.getCharacterStream());
                StringBuffer buf = new StringBuffer();
                while (str != null) {
                   str = in.readLine();
                   if (str != null) {
                      buf.append(str);
                   }
        
                }
                sResult = buf.toString();
             return sResult;
          }
          catch (Exception e) {
             e.printStackTrace();
          }
        return sResult;
       }

0 0