Hibernate session.close()没有返回到池的连接

Per*_*123 14 session hibernate ejb jta

我的应用程序已经长期运行的事务,因此我想在每一个方法的末尾选择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>
Run Code Online (Sandbox Code Playgroud)

我们在连接到Oracle DB的应用程序层使用JSF和EJB 2.1.在after_statement似乎没有释放到连接池.如果您需要更多详细信息,请与我们联系.

Pas*_*ent 20

我在我的应用程序中使用JTA事务.在hibernate.cfg.xml中,我将connection.release_mode设置为auto(默认值),将connection.autocommit设置为true.

您可以尝试明确定义hibernate.connection.release_mode属性after_statement吗?我知道这应该是默认的,但是,根据你的上下文(你可以使用Spring吗?),auto可能不会按预期运行(参见此处 此处).

供参考,这是表3.4.Hibernate JDBC和Connection Properties写有关该属性的信息hibernate.connection.release_mode:

指定Hibernate何时应释放JDBC连接.默认情况下,将保持JDBC连接,直到会话显式关闭或断开连接.对于应用程序服务器JTA数据源,用于 after_statement在每次JDBC调用后积极地释放连接.对于非JTA连接,通常使用在每个事务结束时释放连接是有意义的 after_transaction.auto将选择after_statementJTA和CMT事务策略以及 after_transactionJDBC事务策略.

例如 auto(默认)| on_close| after_transaction| after_statement

此设置仅影响从中返回的会话 SessionFactory.openSession.对于通过获取的会话 SessionFactory.getCurrentSession,CurrentSessionContext配置使用的 实现控制这些会话的连接释放模式.请参见第2.5节"上下文会话"

如果它没有帮助,请添加有关您的环境和配置的更多详细信息(Spring?),如何获得会话等.


Sal*_*dur 0

如果您使用 JDBCTransactionManager,则当事务结束时,连接将返回到连接池。