Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nullpointer at hibernate begin transaction

I'm using hibernate with connection pooled datasource

<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>

I can see, that the connections are opened successfully in database and it's working ok, but after a while I get the following error message in logs and the server just dies:

 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)

The number of connections in database seems to be ok. The maximum is 75, but practically it never goes over 20. The application deployed in JBOSS 4.2. The memory seems to be also ok when the nullpointer execption happens. I seems to me that something is leaking, but I do not know what. Is it possible, that the connection pool think it have 75 sessions and try to increase that - at the same time the db server has just 20 connections?

I could not replicate it in development environment. I tried to kill/disconnect the sessions, break the network connections. I got different exceptions, but no nullpointerexception. Could anyone give me a hint what to investigate what to focus on?

like image 278
HamoriZ Avatar asked Dec 06 '10 16:12

HamoriZ


2 Answers

It looks like you are using org.hibernate.transaction.JDBCTransactionFactory in JTA environment.

Perhaps you need org.hibernate.transaction.JTATransactionFactory:

<prop key="hibernate.transaction.factory_class">
    org.hibernate.transaction.JTATransactionFactory
</prop>
like image 157
axtavt Avatar answered Sep 23 '22 12:09

axtavt


The problem was that there was a part of the code where the session closing was not in the finally block. If the program throw a hibernate error, the session was left open.

like image 38
HamoriZ Avatar answered Sep 20 '22 12:09

HamoriZ