存和取否要用这个方法:Hibernate.createClob();
他是创立Clob对象的;
他是创立Clob对象的;
解决方案 »
- 大家对养孩子的看法?
- 让spring管理struts1.x的action,怎么actionform里没数据
- TOMCAT启动错误
- webservice用附件传送文件的问题
- 求助:Exception in thread "main" java.lang.NullPointerException
- iBatis中sqlmap resultclass="java.lang.Integer",在代码中如何取返回值?
- struts的问题
- 问题急,请各位大虾们支招阿!。。。。。。。。。。。
- EJB事物回滚问题(在线等待)
- struts 中 html:select 如何提交多个已选option项
- 关于spring 注入问题
- webservice开发问题 急急急
至于怎么用,自己搜下吧,网上很多例子的。
public Object readClob(final Class cls, final String fieldname, final Serializable id) throws DAOException {
HibernateCallback callback = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { session.connection().setAutoCommit(false); Object o = session.load(cls, id, LockMode.READ); StringBuffer result = new StringBuffer();
try { String prop = Character.toUpperCase(fieldname.charAt(0)) + fieldname.substring(1); Method method = cls.getMethod("get" + prop, new Class[0]);
Clob clob = (Clob) method.invoke(o, new Object[0]);
if (clob == null) {
return "";
}
BufferedReader in = new BufferedReader(clob.getCharacterStream());
String c; while ((c = in.readLine()) != null) {
result.append(c);
}
in.close(); } catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
throw new DAOException("读取数据时发生错误", e);
}
return result.toString();
} }; Object obj = getHibernateTemplate().execute(callback);
return obj == null ? "" : obj;
} //读CLOB字段
public Clob readClob2(Class cls, String fieldname, Serializable id) throws DAOException { Object o = getHibernateTemplate().load(cls, id); try { Method method = cls.getMethod("get" + fieldname, new Class[0]);
return (Clob) method.invoke(o, new Object[0]);
} catch (Exception e) {
log.error(e.getMessage());
throw new DAOException("读取数据时发生错误", e);
} }
可以
type="org.springframework.orm.hibernate3.support.ClobStringType"
在实体里那字段上面加
@Type(type = " org.springframework.orm.hibernate3.support.ClobStringType " )
@Lob
byte[] content用content和数据库的clob字段映射