您好,欢迎光临 | 我的主页 | 个人资料 | 短消息 | 好友 | 书签 | 黑名单 |
http://www.javayou.com (添加到收藏夹,设为首页)
当你不能再拥有时,你唯一能做的,就是让自己不要忘记 (手机请访问 http://3g.dlog.cn/javayou)
下一篇:用Commons-Email来发邮件 上一篇:呼风唤雨

Oracle的CLOB在Hibernate中的问题

2006年8月3日(Thursday) 15点12分 作者: 刘冬 天气: 心情: 一般

在测试DLOG4J对Oracle数据库(Oracle 9i R2)的支持时候发现,当表中使用大文本字段CLOB的时候,映射时候类型填写为text,程序出现了下面的两个问题:

首先出现的问题是:不允许的操作: streams type cannot be used in batching

该问题的解决办法比较简单,需要修改使用到大文本对象的batch_size值为0,也就是不使用批操作。

修改配置后再次启动DLOG发现的问题是,当写一篇日记时,日记较小时数据插入成功,当日记内容很长的时候数据插入失败。

解决的办法是在CLOB字段的映射条目中增加参数length,例如

<property name="content" type="text" length="100000"/>

如此两个问题得以解决,其他的功能在Oracle数据库中工作一切正常。

另外还有一个应该注意的是size是Oracle的关键字,不要拿它当作字段名,否则报的错误很怪,很难一眼看出来具体问题所在。

标签: Oracle Hibernate CLOB 
通过电脑发布 #1楼 评论时间:2006-8-3 16:56 (Thursday)

转>>

Hi.

I wrote this in my hibernate.properties and works;

hibernate.jdbc.use_streams_for_binary=true
hibernate.jdbc.batch_size=0

Good luck!

邮箱 | 网址 |  
通过电脑发布 #2楼 评论时间:2006-8-16 10:50 (Wednesday)
改用Oracle 10g的驱动就能解决Clob的问题
邮箱 |  
通过电脑发布 #3楼 评论时间:2006-9-4 12:17 (Monday)
fans

能再详细讲讲吗?

1、如何“需要修改使用到大文本对象的batch_size值为0”,是在hibernate的配置文件中修改吗?

2、我将clob映射为text后,增加了length=40000后,依然出错,但是插入200个字符没有问题。我出错的异常是:ORA-01483: invalid length for DATE or NUMBER bind variable

能将代码贴出吗?

 
通过电脑发布 #4楼 评论时间:2006-9-4 15:18 (Monday)

每个对象的配置都可用写一个batch-size的属性,例如:

<class name="DiaryBean" table="dlog_diary" batch-size="0">

另外你的第二个错误好像跟text无关吧?

邮箱 | 网址 |  
通过电脑发布 #5楼 评论时间:2006-10-9 11:39 (Monday)
最后一个问题必须升级一下jdbc驱动包到最新的10g版本上才行!!!
邮箱 | 网址 |  
通过电脑发布 #6楼 评论时间:2007-5-11 08:18 (Friday)
yangxc
谢谢!
 
通过电脑发布 #7楼 评论时间:2007-5-16 10:01 (Wednesday)

我根据你的步骤改了, 可以插入1000-2000字, 但是多了就不行了

然后报了这个错

AbstractFlushingEventListener - Could not synchronize database state with session <org.hibernate.exception.GenericJDBCException: could not insert: [com.liusoft.dlog4j.beans.DiaryBean]>org.hibernate.exception.GenericJDBCException: could not insert: [com.liusoft.dlog4j.beans.DiaryBean]
 at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(Unknown Source)
 at org.hibernate.exception.SQLStateConverter.convert(Unknown Source)
 at org.hibernate.exception.JDBCExceptionHelper.convert(Unknown Source)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(Unknown Source)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(Unknown Source)
 at org.hibernate.action.EntityInsertAction.execute(Unknown Source)
 at org.hibernate.engine.ActionQueue.execute(Unknown Source)
 at org.hibernate.engine.ActionQueue.executeActions(Unknown Source)
 at org.hibernate.engine.ActionQueue.executeActions(Unknown Source)
 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(Unknown Source)
 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(Unknown Source)
 at org.hibernate.impl.SessionImpl.flush(Unknown Source)
 at org.hibernate.impl.SessionImpl.managedFlush(Unknown Source)
 at org.hibernate.transaction.JDBCTransaction.commit(Unknown Source)
 at com.liusoft.util.db.Hibernate.commit(Hibernate.java:145)
 at com.plurality.persistence.config.InitSessionFactory.commit(InitSessionFactory.java:100)

邮箱 | 网址 |  
姓名: 
邮箱:  {可选}
网址:  {可选} 此评论只有我和写日记的人查阅
校验码: ... <我看不清楚>
网记为您提供手机和互联网同步的个人主页,带给你不一样的体验