Hibernate的Nullpointer开始交易

Ham*_*riZ 5 java hibernate connection-pooling nullpointerexception

我正在使用带有连接池数据源的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>
Run Code Online (Sandbox Code Playgroud)

我可以看到,连接在数据库中成功打开并且工作正常,但过了一段时间我在日志中收到以下错误消息并且服务器刚刚死掉:

 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)
Run Code Online (Sandbox Code Playgroud)

数据库中的连接数似乎没问题.最大值为75,但实际上它永远不会超过20.应用程序部署在JBOSS 4.2中.当nullpointer execption发生时,内存似乎也可以.我觉得有些东西在泄漏,但我不知道是什么.是否有可能,连接池认为它有75个会话并试图增加它 - 同时数据库服务器只有20个连接?

我无法在开发环境中复制它.我试图杀死/断开会话,打破网络连接.我有不同的例外,但没有nullpointerexception.任何人都可以给我一个提示,研究一下要关注什么?

Ham*_*riZ 1

问题在于,有一部分代码的会话关闭不在finally 块中。如果程序抛出休眠错误,会话将保持打开状态。