您的位置:首页 > 数据库 > Oracle

hibernate3.2在容器数据源下的游标过多?

2007-07-15 06:39 162 查看
系统采用hibernate 3.2.0运行在websphere app server 6.0.2下,使用was提供的数据源连接oracle 10g。
dao类中获取hibernate session的方式,都是通过ThreadLocal来的,并且确认会在数据库操作完成之后,在finally中执行Session.close()。 但是运行时间长了以后,出现ORA-01000: maximum open cursors exceeded

我详细翻看了robbin对这个问题的论述,基本得出结论:jdbc规范中要求connection在close的时候自动close它所产生的 statement和result set,但是容器的数据源中的connection,因为倍容器托管了,所以在close的时候,并不会按照jdbc的规范去做,它只是回到连接池,而不 是真正关闭。所以执行Session.close后,但是Statement没有被同时关闭,而且因为仍然被应用也不会被gc,长时间运行就会造成游标过 大。

知道了原因,但是目前没找到解决办法,Session对象似乎没有提供api让我去管理它所创建的Statement。请问大家是如何考虑以及解决这个问题的?有没有相关的文档或者建议?

回复:

我在was数据源属性里面设置了销毁时间,数据库连接隔一段时间就销毁一次重新生成,根据jdbc规范,应该能够清理掉遗留的statement和result set。等几天才能看到效果。

hibernate自己用的statement和resultset它自己会关闭吧,是不是你直接使用了connection而没有关闭statement和resultset呢,没听说过要人工帮hibernate去关闭的。

Hibenate will close its own statements and resultsets, the resson for 'too many cursors' should be in your own code which doesn’t close the statement and result after you finsish your own operation.

在hibernate.org的一个faq上看到了这一条:

Q:After a while, Oracle throws this exception: too many open cursors

A:The Oracle JDBC driver doesn't much like to have its prepared statements cached. Disable PreparedStatement caching for the connection pool.

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐