存和取否要用这个方法:Hibernate.createClob();
他是创立Clob对象的;

解决方案 »

  1.   

    Oracle中插入和读取CLOB型数据时需要用到IO流,MSSQL不用。
    至于怎么用,自己搜下吧,网上很多例子的。
      

  2.   

    下面是我们结合spring以后hibernate读取clob字段的两个方法,在正式项目中使用过,希望能对你有所帮助
    public Object readClob(final Class cls, final String fieldname, final Serializable id) throws DAOException {
    HibernateCallback callback = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { session.connection().setAutoCommit(false); Object o = session.load(cls, id, LockMode.READ); StringBuffer result = new StringBuffer();
    try { String prop = Character.toUpperCase(fieldname.charAt(0)) + fieldname.substring(1); Method method = cls.getMethod("get" + prop, new Class[0]);
    Clob clob = (Clob) method.invoke(o, new Object[0]);
    if (clob == null) {
    return "";
    }
    BufferedReader in = new BufferedReader(clob.getCharacterStream());
    String c; while ((c = in.readLine()) != null) {
    result.append(c);
    }
    in.close(); } catch (Exception e) {
    e.printStackTrace();
    log.error(e.getMessage());
    throw new DAOException("读取数据时发生错误", e);
    }
    return result.toString();
    } }; Object obj = getHibernateTemplate().execute(callback);
    return obj == null ? "" : obj;
    } //读CLOB字段
    public Clob readClob2(Class cls, String fieldname, Serializable id) throws DAOException { Object o = getHibernateTemplate().load(cls, id); try { Method method = cls.getMethod("get" + fieldname, new Class[0]);
    return (Clob) method.invoke(o, new Object[0]);
    } catch (Exception e) {
    log.error(e.getMessage());
    throw new DAOException("读取数据时发生错误", e);
    } }
      

  3.   

    http://www.javaeye.com/topic/5029
      

  4.   

    mapping映射改成text如果你用了spring
    可以
     type="org.springframework.orm.hibernate3.support.ClobStringType"
    在实体里那字段上面加
    @Type(type  =   " org.springframework.orm.hibernate3.support.ClobStringType " )
      

  5.   


    @Lob
    byte[] content用content和数据库的clob字段映射