xukongmoji 发表于 2013-1-14 09:06:29

hibernate操作 oracle clob字段

Clob content = almanacBean.getContributionContent();   almanacBean.setContenteStr(content.getSubString(1, (int)content.length()));
Action 层以String传过来

DAO:
public TbAlmanacContribution savaTbAlmanacContribution(final TbAlmanacContribution tbAlmanacContribution)   2.    {   3.      HibernateCallback callback = new HibernateCallback()   4.      {   5.            public Object doInHibernate(Session session) throws HibernateException, SQLException   6.            {   7.               String content=tbAlmanacContribution.getContenteStr();//获取传过来的string   8.                TbAlmanacContribution temp = tbAlmanacContribution;   9.                temp.setContributionContent(Hibernate.createClob(" "));//首先插入一个空的clob对象   10.                session.saveOrUpdate(temp);//保存   11.                session.flush();   12.                session.refresh(temp, LockMode.UPGRADE);   13.                try14.                {   15.                  SerializableClobsc= (SerializableClob)temp.getContributionContent();//序列化成clob   16.                  Clob wrapclob = sc.getWrappedClob();   17.                  if(wrapclob instanceof CLOB){   18.                        CLOB clob = (CLOB)wrapclob;   19.//                  clob = (oracle.sql.CLOB) temp.getContributionContent();   20.//                  clob.putString(1,content);   21.                        java.io.Writer writer = clob.getCharacterOutputStream();   22.                        writer.write(content);   23.                         writer.close();   24.                  }   25.26.//                      session.saveOrUpdate(temp);   27.//                  tx.commit();   28.29.                } catch(Exception e)   30.                {   31.                  e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.   32.                }   33.                return temp;   34.            }   35.      };   36.      return (TbAlmanacContribution) getHibernateTemplate().execute(callback);   37.    }
读取
页: [1]
查看完整版本: hibernate操作 oracle clob字段