配置Hibernate以从连接池中获取新的连接

配置Hibernate以从连接池中获取新的连接

本文介绍了配置Hibernate以从连接池中获取新的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何配置Hibernate,以便每次调用sessionFactory.openSession()时,它都会连接来自连接池的新连接?连接池由Websphere Application Server管理,并且是JDBC数据源。

谢谢

解决方案

这是默认行为,每个会话将从连接池获得专用连接。

不,他们不是。但是也许第二个连接在为请求启动的事务结束时被释放。看看 hibernate.connection.release_mode ,您可能需要使用 on_close 。但没有关于交易策略的更多细节,不可能说出任何内容。

以我的先前建议,只是不会产生,我不会不知道应用程序服务器的行为。我在什么是正确的方式。


How do I configure Hibernate so that each time I call sessionFactory.openSession() it connects with a new connection from the connection pool? The connection pool is managed by Websphere Application Server and is a JDBC Data Source.

Thanks

解决方案

This is the default behavior, each session will get a dedicated connection from the connection pool.

No they are not. But maybe the second connection gets released at the end of the transaction initiated for the request. Have a look at the hibernate.connection.release_mode configuration parameter, you might want to use on_close. But without more details on your transaction strategy, it's impossible to say anything.

Take my previous advice with a grain of salt, you should just not spawn unmanaged threads and I don't know how the application server will behave. I explain in this other answer what would be the right way.

这篇关于配置Hibernate以从连接池中获取新的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 19:31