Duffblog

前进一步,看看,需要前进更大一步才可以。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  5 随笔 :: 53 文章 :: 5 评论 :: 0 Trackbacks
public AttachmentFile addAttachmentFile(AttachmentFile attachmentFile) {
  try {
   attachmentFile.setAttachmentFileBlob(BLOB.empty_lob());
  } catch (SQLException e) {
   e.printStackTrace();
  }
  AttachmentFile savedAttachmentFile = (AttachmentFile)super.saveObject(attachmentFile);
  getHibernateSession().flush();
  return (AttachmentFile) updateAttachmentFileBlob(savedAttachmentFile);
 }

public AttachmentFile updateAttachmentFileBlob(AttachmentFile attachmentFile) {
  //Connection jdbcConnection = this.getHibernateSession().connection();
  
  if (attachmentFile.getAttachmentFile() != null){
   
   getHibernateSession().refresh(attachmentFile, LockMode.UPGRADE);
   Blob sqlBlob = attachmentFile.getAttachmentFileBlob();
   org.hibernate.lob.SerializableBlob hbmBlob = (org.hibernate.lob.SerializableBlob)sqlBlob;
   BLOB oracleBlob = (BLOB)hbmBlob.getWrappedBlob();
   OutputStream os;
   try {
    os = oracleBlob.getBinaryOutputStream();
    os.write(attachmentFile.getAttachmentFile());
    os.close();
   } catch (Exception e1) {
    throw new  SystemRuntimeException(e1.getMessage(),e1);
   }
  }

对了Blob和Clob,需要先save一个空的Blob(Clob),然后,在update.
posted on 2006-11-03 20:07 追球者 阅读(696) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: