论坛首页 Java企业应用论坛

今天升级hibernate3.2GA遇到一个很奇怪的问题(谢谢大家,已解决)

浏览 12252 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-10-18  
今天看到hibernate3.2ga版出来,赶紧更新。

我原来用的是hibernate3.1.3版本+Spring2.0,结果更新后,我配置的c3p0连接池是死活也连接不上了。

数据库是mysql,它在那里一直"Building new Hibernate SessionFactory".

一口气创建了好多。输出信息是这样的:

....-Building new Hibernate SessionFactory
....-Building new Hibernate SessionFactory
....-Building new Hibernate SessionFactory
....-Building new Hibernate SessionFactory
....-Building new Hibernate SessionFactory

然后报错:

WARN  com.mchange.v2.resourcepool.BasicResourcePool - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@16528a2 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
2006-10-18 02:07:03,125 [main] WARN  org.hibernate.cfg.SettingsFactory - Could not obtain connection metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!


把jar包换成hibernate3.1.3.jar就完全正常,用hibernate3.2GA的包就出上面的错误。


我的配置如下:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>/domain/Admin.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!--connection-->
<prop key="hibernate.connection.driver_class">${hibernate.connection.driver_class}</prop>
<prop key="hibernate.connection.url">${hibernate.connection.url}</prop>
<prop key="hibernate.connection.username">${hibernate.connection.username}</prop>
<prop key="hibernate.connection.password">${hibernate.connection.password}</prop>
<prop key="hibernate.useUnicode">${hibernate.useUnicode}</prop>
<prop key="hibernate.characterEncoding">${hibernate.characterEncoding}</prop>
<prop key="hibernate.autoReconnect">${hibernate.autoReconnect}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.default-lazy-init">${hibernate.default-lazy-init}</prop>
<prop key="hibernate.connection.provider_class">${hibernate.connection.provider_class}</prop>
<!--Connection Pooling-->
<prop key="hibernate.c3p0.max_size">${hibernate.c3p0.max_size}</prop>
<prop key="hibernate.c3p0.min_size">${hibernate.c3p0.min_size}</prop>
<prop key="hibernate.c3p0.timeout">${hibernate.c3p0.timeout}</prop>
<prop key="hibernate.c3p0.max_statements">${hibernate.c3p0.max_statements}</prop>
<prop key="hibernate.c3p0.idle_test_period">${hibernate.c3p0.idle_test_period}</prop>
<prop key="hibernate.c3p0.acquire_increment">${hibernate.c3p0.acquire_increment}</prop>
<prop key="hibernate.c3p0.validate">${hibernate.c3p0.validate}</prop>
</props>
</property>
</bean>



实在是不明白这两个版本的hibernate为什么会造成这种情况,不知道大家有没有出现过这种情况,怎么解决这个问题呢???




问题已解决,谢谢大家!

产生的问题是因为没有配置hibernate.cache.provider_class,很奇怪的问题,在3.1.3版本中缓存提供类并非必须的。而在3.2版本中,则必须配置才可以正常创建连接池。

:) 万分感谢楼下各位的热心!!

   发表时间:2006-10-18  
难道是和MySql的版本有关?

0 请登录后投票
   发表时间:2006-10-18  
我用DBCP就没有问题
c3p0我一直觉得不爽,个人看法
不知道你为什么选择c3p0
0 请登录后投票
   发表时间:2006-10-18  
chinarefers 写道
难道是和MySql的版本有关?


那你用的MySQL数据库版本是?JDBC驱动版本是?

你的c3p0版本是?
可以参考:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2032
0 请登录后投票
   发表时间:2006-10-18  
c3p0: c3p0-0.9.1-pre9.jar
MySql: mysql-5.0.26

当我换DBCP和spring内置的连接池也出现这个情况。

超级奇怪! 实在是晕了。

0 请登录后投票
   发表时间:2006-10-19  
chinarefers 写道
问题已解决,谢谢大家!

产生的问题是因为没有配置hibernate.cache.provider_class,很奇怪的问题,在3.1.3版本中缓存提供类并非必须的。而在3.2版本中,则必须配置才可以正常创建连接池。


今天看了一下Hibernate3.2的Reference,果然如此:

引用
A Hibernate Session is a transaction-level cache of persistent data. It is possible to configure a cluster or JVM-level (SessionFactory-level) cache on a class-by-class and collection-by-collection basis. You may even plug in a clustered cache. Be careful. Caches are never aware of changes made to the persistent store by another application (though they may be configured to regularly expire cached data).

You have the option to tell Hibernate which caching implementation to use by specifying the name of a class that implements org.hibernate.cache.CacheProvider using the property hibernate.cache.provider_class. Hibernate comes bundled with a number of built-in integrations with open-source cache providers (listed below); additionally, you could implement your own and plug it in as outlined above. Note that versions prior to 3.2 defaulted to use EhCache as the default cache provider; that is no longer the case as of 3.2.

就是说在3.2版本中,如果hibernate.cache.use_second_level_cache被设定为true,那么我们需要自己设定一下hibernate.cache.provider_class的类名。因为现在的Hibernate已经不再有默认的hibernate.cache.provider_class了。
1 请登录后投票
   发表时间:2006-10-23  
谢谢Allen,hibernate的二级缓存定义应该是默认为true的吧,因为我并没有特别配置二级缓存。

最近一直是直接使用最新的包,没有看Reference,嘿嘿。

看到你贴出来的这段,我才发现有这个改变,多谢多谢!!

0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics