我的应用程序有长时间运行的事务,因此我在每个方法末尾尝试了选项 session.close() 以确保连接对象不会无限期地保留很长时间。
当使用 session.close() 选项时,我可以看到 Hibernate 的会话对象和从 session.connection() 获取的相应 Connection 对象被正确销毁。但问题出在连接池上。即使关闭会话后,会话获得的连接也不会释放回连接池。发现其他请求正在等待池中的连接。
我在我的应用程序中使用 JTA 事务。在 hibernate.cfg.xml 中,我将 connection.release_mode 设置为 auto (默认),将 connection.autocommit 设置为 true。
有人遇到过这个问题吗?请让我知道我在这里缺少什么。
后续:这是我的hibernate配置文件详细信息:
<property name="connection.datasource">MXoraDS</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.release_mode">after_statement</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</property>
<property name="transaction.auto_close_session">true</property>
<property name="max_fetch_depth">2</property>
我们在连接Oracle DB的应用层使用JSF和EJB 2.1。 after_statement
似乎没有释放到池的连接。如果您需要更多详细信息,请告诉我。
My application has long running transactions and hence I tried the option session.close() at the end of every method to ensure that the connection objects are not held indefinitely for long time.
When session.close() option is used, I could see that the Hibernate's session object and the corresponding Connection object obtained from session.connection() are destroyed properly. But the issue is with the connection pool. The connection obtained by the session is not released back to the connection pool even after closing the session. Other requests are found waiting for connection from the pool.
I am using JTA transaction in my application. In hibernate.cfg.xml, I have set connection.release_mode to auto (default) and connection.autocommit to true.
Has anyone faced this issue? Please let me know what am I missing here.
Follow-up: This is my hibernate configuration file details:
<property name="connection.datasource">MXoraDS</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.release_mode">after_statement</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</property>
<property name="transaction.auto_close_session">true</property>
<property name="max_fetch_depth">2</property>
We use JSF and EJB 2.1 at the application layer connecting to Oracle DB. The after_statement
doesn't seem to release the connection to the pool. Please let me know if u need any more details.
发布评论
评论(2)
您可以尝试将
hibernate.connection.release_mode
属性显式定义为after_statement
吗?我知道这应该是默认设置,但是,根据您的上下文(您可以使用 Spring 吗?),auto
可能不会按预期运行(请参阅 此处 和 此处)。作为参考,以下是 表 3.4。 Hibernate JDBC 和连接属性 写了有关属性
hibernate.connection.release_mode
的内容:如果没有帮助,请添加有关您的环境和配置(Spring?)、如何获取会话等的更多详细信息。
Could you try to define the
hibernate.connection.release_mode
property toafter_statement
explicitly? I know this is supposed to be the default but, depending on your context (could you be using Spring?),auto
might not behave as expected (see here and here).For reference, here is what the Table 3.4. Hibernate JDBC and Connection Properties writes about the property
hibernate.connection.release_mode
:If it doesn't help, please add more details about your environment and configuration (Spring?), how you get the session, etc.
如果您使用 JDBCTransactionManager,则当事务结束时,连接将返回到连接池。
if you are using the JDBCTransactionManager, the connection will be returned to the connectionpool when the transactions ends.