Announcement Announcement Module
Collapse
No announcement yet.
DB connection leak with declarative JTA transaction on Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DB connection leak with declarative JTA transaction on Hibernate

    Hi,

    I've recently started using/learning Spring for one of my new project. I intend to persist POJOs using Hibernate3 and Spring2. For transactional boundary I'm using Spring's AOP declarative Tx methodology. As I'm using Weblogic app server I've used Spring's Weblogic specific TxManager (WebLogicJtaTransactionManager). I've enabled "Emulate Two-Phase Commit for non-XA Driver" for the datasource as I'm using a non-XA DB driver. I get the exception mentioned below only when I use MultipleHiLoPerTableGenerator (as it tried to initiate a new Tx within a Tx).

    Code:
    2007-07-11 10:33:43.056 Z020    SEVERE  Cannot call Connection.commit in distrib
    uted transaction.  Transaction Manager will commit the resource manager when the
     distributed transaction is committed.  org.hibernate.util.JDBCExceptionReporter
    
    <Jul 11, 2007 10:33:43 AM CDT> <Warning> <JDBC> <BEA-001074> <A JDBC pool connec
    tion leak was detected. A connection leak occurs when a connection obtained from
     the pool was not closed explicitly by calling close() and then was disposed by
    the garbage collector and returned to the connection pool. The following stack t
    race at create shows where the leaked connection was created.  Stack trace at co
    nnection create:
    
            at weblogic.jdbc.wrapper.JTSConnection.initCopy(JTSConnection.java:201)
            at weblogic.jdbc.jts.Driver.copyConnection(Driver.java:277)
            at weblogic.jdbc.jts.Driver.copyLocalConnection(Driver.java:257)
            at weblogic.jdbc.jts.Driver.connect(Driver.java:147)
            at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSour
    ce.java:329)
            at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.
    getConnection(LocalDataSourceConnectionProvider.java:81)
            at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.jav
    a:495)
            at org.hibernate.engine.transaction.Isolater$JdbcDelegate.delegateWork(I
    solater.java:147)
            at org.hibernate.engine.transaction.Isolater.doIsolatedWork(Isolater.jav
    a:38)
            at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(Transac
    tionHelper.java:51)
            at org.hibernate.id.MultipleHiLoPerTableGenerator.generate(MultipleHiLoP
    erTableGenerator.java:183)
            at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId
    (AbstractSaveEventListener.java:91)
            at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGene
    ratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
            at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrR
    equestedId(DefaultSaveEventListener.java:33)
            at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTran
    sient(DefaultSaveOrUpdateEventListener.java:175)
            at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(
    DefaultSaveEventListener.java:27)
            at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpda
    te(DefaultSaveOrUpdateEventListener.java:70)
            at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
            at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
            at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
            at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate
    (HibernateTemplate.java:635)
            at org.springframework.orm.hibernate3.HibernateTemplate.execute(Hibernat
    eTemplate.java:372)
            at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTe
    mplate.java:632)
            at mypkg.mytrade.persistance.TradeDAOImpl.insertTrade(TradeDAOIm
    pl.java:34)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
    on(AopUtils.java:296)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
    inpoint(ReflectiveMethodInvocation.java:177)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
    ReflectiveMethodInvocation.java:144)
            at org.springframework.transaction.interceptor.TransactionInterceptor.in
    voke(TransactionInterceptor.java:107)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
    ReflectiveMethodInvocation.java:166)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
    cAopProxy.java:204)
            at $Proxy9.insertTrade(Unknown Source)
            at mypkg.mytrade.persistance.TradeManager.handleTrade(TradeManag
    er.java:38)
            at mypkg.mytrade.processor.TradeProcessorImpl.handleTradePersist
    ance(TradeProcessorImpl.java:56)
            at mypkg.mytrade.listener.TradeListener.processMessage(TradeList
    ener.java:90)
            at mypkg.mytrade.listener.TradeListener.onMessage(TradeListener.
    java:77)
            at weblogic.ejb20.internal.MDListener.execute(MDListener.java:400)
            at weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.
    java:333)
            at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:298)
            at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2686)
            at weblogic.jms.client.JMSSession.execute(JMSSession.java:2598)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    Spring config for the application is as follows -

    Code:
    <jee:jndi-lookup id="myTradeDataSource" jndi-name="sybaseDS"/>	
    
    <bean id="jtaTransactionManager" 
    	class="org.springframework.transaction.jta.WebLogicJtaTransactionManager">
    </bean>        
    
    <bean id="myHibernateTradeDAO" 
    			class="mypkg.mytrade.persistance.TradeDAOImpl">
    		<property name="sessionFactory" ref="sessionFactory"/>		
    </bean>
    
    <bean id="sessionFactory"
    	class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    	<property name="dataSource" ref="myTradeDataSource"/>				
    	<property name="hibernateProperties">
    	<util:properties location="classpath:hbm/hibernate.properties"/>
    </property>
    	<property name="mappingResources">
    		<list>
    			<value>hbm/myTrade.hbm.xml</value>
    		</list>
    	</property>		
    </bean>
    
    <tx:advice id="txAdvice" transaction-manager="jtaTransactionManager">	
    	<tx:attributes>			
    		<tx:method name="fetchTrade" read-only="true"/>						
    		<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" timeout="480" rollback-for="mypkg.mytrade.exception.SystemException"/>
    		
    
    	</tx:attributes>
    </tx:advice>
    	
    <aop:config>
    	<aop:pointcut id="hibernateTradeDAOOperation"
    		expression="execution(* mypkg.mytrade.persistance.TradeDAO.*(..))"/>
    	<aop:advisor advice-ref="txAdvice" pointcut-ref="hibernateTradeDAOOperation"/>
    </aop:config>
    Hibernate properties -

    Code:
    hibernate.dialect=org.hibernate.dialect.Sybase11Dialect
    hibernate.show_sql=true
    hibernate.connection.autocommit=false
    MDB's transactional attribute is "Required".

    Thanks in advance,
    Ashok

  • #2
    Please help if anyone has encountered such a problem.

    Comment

    Working...
    X