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);
}
读取