hibernate中clob类型值

jxfc888 2008-11-30 04:45:16
hibernate怎么取不到clob类型的字段值,取出来为空(数据库中是存在的)
知道的说下,很急
...全文
78 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dddzizi 2008-12-03
  • 打赏
  • 举报
回复

clob转换成 byte[]
ahlon 2008-12-01
  • 打赏
  • 举报
回复

@Lob
byte[] content

用content和数据库的clob字段映射
handong890 2008-12-01
  • 打赏
  • 举报
回复
mapping映射改成text

如果你用了spring
可以
type="org.springframework.orm.hibernate3.support.ClobStringType"
在实体里那字段上面加
@Type(type = " org.springframework.orm.hibernate3.support.ClobStringType " )
boboo_2000_0 2008-12-01
  • 打赏
  • 举报
回复
没有用过,关注!~~
千骑卷平冈 2008-12-01
  • 打赏
  • 举报
回复
Oracle中插入和读取CLOB型数据时需要用到IO流,MSSQL不用。
至于怎么用,自己搜下吧,网上很多例子的。
zou_wei_forever 2008-12-01
  • 打赏
  • 举报
回复
http://www.javaeye.com/topic/5029
toss2000 2008-12-01
  • 打赏
  • 举报
回复
下面是我们结合spring以后hibernate读取clob字段的两个方法,在正式项目中使用过,希望能对你有所帮助


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

}
然月枕流君 2008-11-30
  • 打赏
  • 举报
回复
存和取否要用这个方法:Hibernate.createClob();
他是创立Clob对象的;
fosjos 2008-11-30
  • 打赏
  • 举报
回复
不会是直接取的吧,要转换的,找找吧

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧