Hibernate 不释放数据库连接
以下是配置细节:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9iDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.OSCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">update</prop>-->
<!-- HIBERNATE CONNECTION POOLING!!-->
<prop key="c3p0.acquire_increment">5</prop>
<prop key="c3p0.idle_test_period">100</prop>
<!-- seconds -->
<prop key="c3p0.max_statements">5</prop>
<prop key="c3p0.min_size">15</prop>
<prop key="c3p0.max_size">100</prop>
<prop key="c3p0.timeout">100</prop>
<!-- seconds -->
</props>
</property>
我们的应用程序是通过 Spring & 开发的。冬眠。
一旦我们启动应用程序并点击它,它就会打开 140 个连接并且不会释放它。
我们的 DAO 看起来像这样:
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
...
public class ActionDAO extends HibernateDaoSupport implements IActionDAO {
public Action findById(ActionPK actionPK) {
return (Action) getHibernateTemplate().get(Action.class, actionPK);
}
public void add(Action action) {
getHibernateTemplate().save(action);
}
}
Following is the configuration details:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9iDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.OSCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">update</prop>-->
<!-- HIBERNATE CONNECTION POOLING!!-->
<prop key="c3p0.acquire_increment">5</prop>
<prop key="c3p0.idle_test_period">100</prop>
<!-- seconds -->
<prop key="c3p0.max_statements">5</prop>
<prop key="c3p0.min_size">15</prop>
<prop key="c3p0.max_size">100</prop>
<prop key="c3p0.timeout">100</prop>
<!-- seconds -->
</props>
</property>
Our application is developed through Spring & Hibernate.
Once we bring the application up and hit it, its opening 140 connections and not releasing it.
Our DAO looks like this:
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
...
public class ActionDAO extends HibernateDaoSupport implements IActionDAO {
public Action findById(ActionPK actionPK) {
return (Action) getHibernateTemplate().get(Action.class, actionPK);
}
public void add(Action action) {
getHibernateTemplate().save(action);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(6)
贪了杯2024-09-02 00:14:27
如果您正在使用 spring 自动装配和 hibernateTemplate,
请确保您没有创建多个 HibernateTemplate 实例,即
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/applicationContext.xml");
Object o=context.getBean("hibernateTemplate");
对象 o
必须缓存在某处,并在您的应用程序代码请求实例时返回休眠模板。
谢谢
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
前段时间我们也遇到过类似的问题,根本原因是应用程序终止之前 Hibernate 会话工厂没有关闭。虽然我知道您正在使用 Spring,它应该自动处理这个问题,但仍然值得检查。
We had a similar issue some time ago, and the root cause was that the Hibernate session factory was not closed before the app terminated. Although I understand that you are using Spring, which is supposed to take care of this automagically, still it might be worth checking.