`
ghost_fly
  • 浏览: 108737 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

Hibernate 操作CLOb

阅读更多
   Clob content = almanacBean.getContributionContent();
            almanacBean.setContenteStr(content.getSubString(1, (int) content.length()));

 Action 层以String传过来

 

DAO:

 public TbAlmanacContribution savaTbAlmanacContribution(final TbAlmanacContribution tbAlmanacContribution)
    {
        HibernateCallback callback = new HibernateCallback()
        {
            public Object doInHibernate(Session session) throws HibernateException, SQLException
            {
                 String content=tbAlmanacContribution.getContenteStr();//获取传过来的string
                TbAlmanacContribution temp = tbAlmanacContribution;
                temp.setContributionContent(Hibernate.createClob(" "));//首先插入一个空的clob对象
                session.saveOrUpdate(temp);//保存
                session.flush();
                session.refresh(temp, LockMode.UPGRADE);
                try
                {
                    SerializableClob  sc= (SerializableClob)temp.getContributionContent();//序列化成clob
                    Clob wrapclob = sc.getWrappedClob();
                    if(wrapclob instanceof CLOB){
                        CLOB clob = (CLOB)wrapclob;
//                    clob = (oracle.sql.CLOB) temp.getContributionContent();
//                    clob.putString(1,content);
                        java.io.Writer writer = clob.getCharacterOutputStream();
                        writer.write(content);
                         writer.close();
                    }

//                      session.saveOrUpdate(temp);
//                    tx.commit();

                } catch(Exception e)
                {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
                return temp;
            }
        };
        return (TbAlmanacContribution) getHibernateTemplate().execute(callback);
    }

 读取

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics