Atomikos with Hibernate will exhaust db connections

Posted by peter on Stack Overflow See other posts from Stack Overflow or by peter
Published on 2010-04-04T16:51:49Z Indexed on 2010/04/04 17:13 UTC
Read the original article Hit count: 430

Filed under:
|
|
|

I am testing an application (Spring 2.5, Hibernate 3.5.0 Beta, Atomikos 3.6.2, and Postgreql 8.4.2) with the configuration for the DAO listed below. The problem that I see is that the pool of 10 connections with the dataSource gets exhausted after the 10's transaction. I know 'hibernate.connection.release_mode' has no effect unless the session is obtained with openSession rather then using a contextual session. I am wandering if anyone has found a way to instruct atomikos code to release connections after any transaction. Thank you

Peter

<bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
    <property name="uniqueResourceName"><value>XADBMS</value></property>
    <property name="xaDataSourceClassName">
        <value>org.postgresql.xa.PGXADataSource</value>
    </property>
    <property name="xaProperties">
        <props>
            <prop key="databaseName">${jdbc.name}</prop>
            <prop key="serverName">${jdbc.server}</prop>
            <prop key="portNumber">${jdbc.port}</prop>
            <prop key="user">${jdbc.username}</prop>
            <prop key="password">${jdbc.password}</prop>
        </props>        
    </property>
    <property name="poolSize"><value>10</value></property>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="mappingResources">
        <list>
            <value>Abc.hbm.xml</value>          
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
            <prop key="hibernate.show_sql">on</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.connection.isolation">3</prop> 
            <prop key="hibernate.current_session_context_class">jta</prop> 
            <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop> 
            <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>   
            <prop key="hibernate.connection.release_mode">auto</prop>
            <prop key="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</prop>      
            <prop key="hibernate.transaction.auto_close_session">true</prop>
        </props>
    </property>
</bean>
<!-- Transaction definition here -->
<bean id="userTransactionService"  
  class="com.atomikos.icatch.config.UserTransactionServiceImp"  
  init-method="init" destroy-method="shutdownForce"> 
    <constructor-arg> 
        <props> 
            <prop key="com.atomikos.icatch.service"> 
              com.atomikos.icatch.standalone.UserTransactionServiceFactory 
            </prop> 
        </props> 
    </constructor-arg>  
</bean> 

<!--  Construct Atomikos UserTransactionManager, needed to configure Spring  --> 
<bean id="AtomikosTransactionManager"  
      class="com.atomikos.icatch.jta.UserTransactionManager"  
      init-method="init" destroy-method="close"  
      depends-on="userTransactionService"> 
   <property name="forceShutdown" value="false" /> 
</bean> 

<!-- Also use Atomikos UserTransactionImp, needed to configure Spring  -->  
<bean id="AtomikosUserTransaction"  class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService"> 
   <property name="transactionTimeout" value="300" /> 
</bean> 

<!--  Configure the Spring framework to use JTA transactions from Atomikos  --> 
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"  
      depends-on="userTransactionService"> 
   <property name="transactionManager" ref="AtomikosTransactionManager" /> 
   <property name="userTransaction" ref="AtomikosUserTransaction" /> 
</bean> 

    <!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean below) -->
<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <!-- all methods starting with 'get' are read-only -->
        <tx:method name="get*" read-only="true" propagation="REQUIRED"/>
        <!-- other methods use the default transaction settings (see below) -->
        <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
</tx:advice>    

<aop:config>
    <aop:advisor pointcut="execution(* *.*.AbcDao.*(..))" advice-ref="txAdvice"/>
</aop:config>

    <!-- DAO objects -->
<bean id="abcDao" class="test.dao.impl.HibernateAbcDao" scope="singleton">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

© Stack Overflow or respective owner

Related posts about spring

Related posts about hibernate