Hibernate4 使用Proxool连接数据库出现 at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer

其实只要看第一行就可以了 at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:244) ,就是在配置的时候没取到值。那么为什么没取到值呢,是因为Hibernate默认是使用jdbc方式来取的,如果使用连接池的方式的话,必须告诉Hibernate一声,让它不使用单纯的JDBC连接。加入下面这一句话就可以了。

<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>

这问题也困扰了我好几个小时,下面贴出Hibernate的源码来看一下。


package org.hibernate.engine.jdbc.internal;

		// 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic value.
		// The need for it is intended to be alleviated with future development, thus it is
		// not defined as an Environment constant...
		//
		// it is used to control whether we should consult the JDBC metadata to determine
		// certain Settings default values; it is useful to *not* do this when the database
		// may not be available (mainly in tools usage).
		final boolean useJdbcMetadata = ConfigurationHelper.getBoolean( "hibernate.temp.use_jdbc_metadata_defaults", configValues, true );
		if ( useJdbcMetadata ) {
			try {
				final Connection connection = jdbcConnectionAccess.obtainConnection();

大家可以看到,参数在取值的时候,它要先用useJdbcMetadata判断一下,是不是JDBC方式,如果不把这个属性设置为false的话,那么取值必然是取不到了,这就是空指针的原因。


PS:以后开源的东西还是要多看看源码

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值