hibernate c3p0破管 [英] hibernate c3p0 broken pipe

查看:169
本文介绍了hibernate c3p0破管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将hibernate 3与c3p0结合使用,用于不断从某些源提取数据并将其写入数据库的程序。
现在的问题是,数据库可能由于某些原因而变得不可用(在最简单的情况下:我简单地关闭它)。



如果有任何事情写入数据库不应该有任何异常 - 查询应等待所有永久性,直到数据库再次可用。
如果我没有弄错,这是连接池可以为我做的事情之一:如果数据库有问题,只需重试连接 - 最糟糕的情况是无限。



但是,我得到一个破损的管道异常,有时候连接被拒绝,然后异常传递给我自己的代码,这应该不会发生。



即使我发现异常,我又能干净地重新初始化hibernate吗? (到目前为止,没有c3p0,我只是再次构建会话工厂,但如果可能会泄漏连接(或者可以这么做),我不会感到惊讶。)



<数据库是Virtuoso开源版本。



我的hibernate.xml.cfg c3p0配置:

 < property name =hibernate.connection.provider_class> org.hibernate.connection.C3P0ConnectionProvider< / property> 
< property name =hibernate.c3p0.breakAfterAcquireFailure> false< / property>
< property name =hibernate.c3p0.acquireRetryAttempts> -1< / property>
< property name =hibernate.c3p0.acquireRetryDelay> 30000< / property>
< property name =hibernate.c3p0.automaticTestTable> my_test_table< / property>

< property name =hibernate.c3p0.initialPoolSize> 3< / property>
< property name =hibernate.c3p0.minPoolSize> 3< / property>
< property name =hibernate.c3p0.maxPoolSize> 10< / property>



btw:测试表已创建,并且我得到大量的调试输出 - 所以它看起来实际上读取配置。

解决方案

好像BoneCP实际上已经实现了这一点。它可以设置为记录事务并在网络或数据库故障时重播它。

http://jolbox.com/bonecp/downloads/site/apidocs/com/jolbox/bonecp/BoneCPConfig.html #setTransactionRecoveryEnabled(布尔值)


I'm using hibernate 3 with c3p0 for a program which constantly extracts data from some source and writes it to a database. Now the problem is, that the database might become unavailable for some reasons (in the simplest case: i simply shut it down).

If anything is about to be written to the database there should not be any exception - the query should wait for all eternity until the database becomes available again. If I'm not mistaken this is one of the things the connection pool could do for me: if there is a problem with the db, just retry to connect - in the worst case for infinity.

But instead i get a broken pipe exception, sometimes followed by connection refused and then the exception is passed to my own code, which shouldn't happen.

Even if I catch the exception, how could i cleanly reinitialize hibernate again? (So far without c3p0 i simply built the session factory again, but i wouldn't be surprised if that could leak connections (or is it ok to do so?)).

The database is Virtuoso open source edition.

My hibernate.xml.cfg c3p0 config:

<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>  
<property name="hibernate.c3p0.breakAfterAcquireFailure">false</property>
<property name="hibernate.c3p0.acquireRetryAttempts">-1</property>
<property name="hibernate.c3p0.acquireRetryDelay">30000</property>
<property name="hibernate.c3p0.automaticTestTable">my_test_table</property>

<property name="hibernate.c3p0.initialPoolSize">3</property>
<property name="hibernate.c3p0.minPoolSize">3</property>
<property name="hibernate.c3p0.maxPoolSize">10</property>

btw: The test table is created and i get tons of debug output- so it seems it actually reads the config.

解决方案

Well it seems that BoneCP has actually implemented this. It can be set to record the transaction and replay it upon network or database failure:

http://jolbox.com/bonecp/downloads/site/apidocs/com/jolbox/bonecp/BoneCPConfig.html#setTransactionRecoveryEnabled(boolean)

这篇关于hibernate c3p0破管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆