[英]Nullpointer at hibernate begin transaction
我正在使用帶有連接池數據源的hibernate
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property name="connectionCachingEnabled" value="true" />
<property name="URL">
<value>${jdbc.url}</value>
</property>
<property name="user">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="connectionCacheProperties">
<value>
MinLimit:10
MaxLimit:75
InitialLimit:10
ConnectionWaitTimeout:120
InactivityTimeout:180
ValidateConnection:true
MaxStatementsLimit:0
</value>
</property>
</bean>
<bean id="hibernatePropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="hibernate.properties"/>
</bean>
<!-- Database Property -->
<bean id="hibernatePropertiesPearl"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.cache.provider_class">MyCacheProvider</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.max_fetch_depth">0</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.JBossTransactionManagerLookup
</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
<prop key="hibernate.transaction.auto_close_session">false</prop>
</props>
</property>
</bean>
我可以看到,連接在數據庫中成功打開並且工作正常,但過了一段時間我在日志中收到以下錯誤消息並且服務器剛剛死掉:
21:48:20,700 ERROR [RentalAgreementServlet] Generic exception occurred
java.lang.NullPointerException
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
at HibernateUtil.currentSession(HibernateUtil.java:116)
數據庫中的連接數似乎沒問題。 最大值為75,但實際上它永遠不會超過20.應用程序部署在JBOSS 4.2中。 當nullpointer execption發生時,內存似乎也可以。 我覺得有些東西在泄漏,但我不知道是什么。 是否有可能,連接池認為它有75個會話並試圖增加它 - 同時數據庫服務器只有20個連接?
我無法在開發環境中復制它。 我試圖殺死/斷開會話,打破網絡連接。 我有不同的例外,但沒有nullpointerexception。 任何人都可以給我一個提示,研究一下要關注什么?
看起來您在JTA環境中使用org.hibernate.transaction.JDBCTransactionFactory
。
也許你需要org.hibernate.transaction.JTATransactionFactory
:
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</prop>
問題是代碼中有一部分會話關閉不在finally塊中。 如果程序拋出一個休眠錯誤,則會話保持打開狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.