需要在hbm.xml配置文件的blob属性上加上type属性
<property name="xxx" type="blob">
这样,hibernate会用不同于其他字段的方式处理这个字段

解决方案 »

  1.   

    对csdn有点失望
    问题已已经解决
    比较兴奋
    楼上的谢谢留言
    结贴
      

  2.   

    问题是怎么解决的?能否share一下!
      

  3.   

    public static void saveReceiveMail(Receivemail receivemail,byte[] content) throws DAOException {  
    BaseDAO dao = new BaseDAO();     
    try { 
    Session session = dao.getSession();
    Transaction tx = session.beginTransaction();
    byte[] buffer = new byte[1];
    buffer[0] = 1;
    receivemail.setFilecontent(Hibernate.createBlob(buffer) );
    session.save(receivemail);
    session.flush();
    session.refresh(receivemail, LockMode.UPGRADE);
    SerializableBlob blob = (org.hibernate.lob.SerializableBlob)receivemail.getFilecontent();
    Blob wb = blob.getWrappedBlob();
    if (wb instanceof BLOB) { 
                BLOB image = (BLOB) wb;
                OutputStream out = image.getBinaryOutputStream();
                out.write(content, 0, content.length);   //这里自己改成你的数据            out.flush();
                out.close();}
    tx.commit();
    session.close();

         }catch (SQLException e) {
    throw new DAOException(e, "查找数据失败!");
    } catch (IOException e) {
    throw new DAOException(e, "数据传输失败!");

    }
      

  4.   

    4k以上做特殊处理
    bolb类型的
    先插入空的在更新进去
    就好了的