-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem keeping open session
PostPosted: Thu Dec 02, 2010 9:25 am 
Newbie

Joined: Thu Dec 02, 2010 9:09 am
Posts: 1
Hi!

I have a batch process inJava using Spring+Hibernate. I want to keep session open for all access to Oracle. Here is my configuration:

Code:
   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource"><ref local="dataSource"/></property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.use_outer_join">${hibernate.use_outer_join}</prop>
            <prop key="hibernate.jdbc.use_streams_for_binary">$(hibernate.jdbc.use_streams_for_binary)</prop>
            <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.connection.pool_size">${hibernate.connection.pool_size}</prop>
         </props>
      </property>
      <property name="annotatedClasses">
         <list>...</list>   
      </property>
   </bean>

   <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory"><ref local="sessionFactory"/></property>
   </bean>
   <bean id="itemDAOrl"
      class="app.data.dao.hibernate.ItemDAOHibernate">
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
   </bean>

   <bean id="itemDAO"
      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="target">
         <ref local="itemDAOrl" />
      </property>
      <property name="transactionManager" ref="transactionManager" />
      <property name="transactionAttributes">
         <props>
            <prop key="*">PROPAGATION_REQUIRED</prop>
         </props>
      </property>
   </bean>


I access DB :

Code:
getHibernateTemplate().find(_query, new Object[]{_param0});


But my log shows that every session is closed:
Quote:
[ASF_BATCH] [02 dic 2010 13:52:59,219] DEBUG SessionFactoryUtils.doGetSession(318) | Opening Hibernate Session
[ASF_BATCH] [02 dic 2010 13:52:59,219] DEBUG TransactionSynchronizationManager.bindResource(174) | Bound value [org.springframework.orm.hibernate3.SessionHolder@21a79071] for key [org.hibernate.impl.SessionFactoryImpl@2143ed74] to thread [main]
[ASF_BATCH] [02 dic 2010 13:52:59,219] DEBUG TransactionSynchronizationManager.getResource(146) | Retrieved value [org.springframework.orm.hibernate3.SessionHolder@21a79071] for key [org.hibernate.impl.SessionFactoryImpl@2143ed74] bound to thread [main]
[ASF_BATCH] [02 dic 2010 13:52:59,220] DEBUG HibernateTransactionManager.doGetTransaction(411) | Found thread-bound Session [org.hibernate.impl.SessionImpl@7ffbfbf9] for Hibernate transaction
[ASF_BATCH] [02 dic 2010 13:52:59,220] DEBUG AbstractPlatformTransactionManager.getTransaction(346) | Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@785bda13]
[ASF_BATCH] [02 dic 2010 13:52:59,220] DEBUG AbstractPlatformTransactionManager.getTransaction(374) | Creating new transaction with name [app.data.dao.ItemDAO.getEmpFromC]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
[ASF_BATCH] [02 dic 2010 13:52:59,220] DEBUG HibernateTransactionManager.doBegin(460) | Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@7ffbfbf9]
[ASF_BATCH] [02 dic 2010 13:52:59,220] DEBUG DriverManagerDataSource.getConnectionFromDriverManager(279) | Creating new JDBC Connection to [jdbc:oracle:thin:@******]
[ASF_BATCH] [02 dic 2010 13:52:59,265] DEBUG HibernateTransactionManager.doBegin(523) | Exposing Hibernate transaction as JDBC transaction [oracle.jdbc.driver.T4CConnection@564a5320]
[ASF_BATCH] [02 dic 2010 13:52:59,265] DEBUG TransactionSynchronizationManager.bindResource(174) | Bound value [org.springframework.jdbc.datasource.ConnectionHolder@29978622] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@5a9b8ff9] to thread [main]
[ASF_BATCH] [02 dic 2010 13:52:59,266] DEBUG TransactionSynchronizationManager.initSynchronization(228) | Initializing transaction synchronization
[ASF_BATCH] [02 dic 2010 13:52:59,266] DEBUG TransactionAspectSupport.prepareTransactionInfo(290) | Getting transaction for [app.data.dao.ItemDAO.getEmpFromC]
[ASF_BATCH] [02 dic 2010 13:52:59,266] DEBUG TransactionSynchronizationManager.getResource(146) | Retrieved value [org.springframework.orm.hibernate3.SessionHolder@21a79071] for key [org.hibernate.impl.SessionFactoryImpl@2143ed74] bound to thread [main]
[ASF_BATCH] [02 dic 2010 13:52:59,267] DEBUG TransactionSynchronizationManager.getResource(146) | Retrieved value [org.springframework.orm.hibernate3.SessionHolder@21a79071] for key [org.hibernate.impl.SessionFactoryImpl@2143ed74] bound to thread [main]
[ASF_BATCH] [02 dic 2010 13:52:59,267] DEBUG HibernateTemplate.doExecute(410) | Found thread-bound Session for HibernateTemplate
[ASF_BATCH] [02 dic 2010 13:52:59,267] DEBUG TransactionSynchronizationManager.getResource(146) | Retrieved value [org.springframework.orm.hibernate3.SessionHolder@21a79071] for key [org.hibernate.impl.SessionFactoryImpl@2143ed74] bound to thread [main]
[ASF_BATCH] [02 dic 2010 13:52:59,273] DEBUG HibernateTemplate.doExecute(435) | Not closing pre-bound Hibernate Session after HibernateTemplate
[ASF_BATCH] [02 dic 2010 13:52:59,273] DEBUG TransactionAspectSupport.commitTransactionAfterReturning(319) | Completing transaction for [app.data.dao.ItemDAO.getEmprFromC]
[ASF_BATCH] [02 dic 2010 13:52:59,274] DEBUG AbstractPlatformTransactionManager.triggerBeforeCommit(880) | Triggering beforeCommit synchronization
[ASF_BATCH] [02 dic 2010 13:52:59,274] DEBUG AbstractPlatformTransactionManager.triggerBeforeCompletion(893) | Triggering beforeCompletion synchronization
[ASF_BATCH] [02 dic 2010 13:52:59,274] DEBUG AbstractPlatformTransactionManager.processCommit(707) | Initiating transaction commit
[ASF_BATCH] [02 dic 2010 13:52:59,274] DEBUG HibernateTransactionManager.doCommit(602) | Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@7ffbfbf9]
[ASF_BATCH] [02 dic 2010 13:52:59,275] DEBUG AbstractPlatformTransactionManager.triggerAfterCommit(906) | Triggering afterCommit synchronization
[ASF_BATCH] [02 dic 2010 13:52:59,276] DEBUG AbstractPlatformTransactionManager.triggerAfterCompletion(922) | Triggering afterCompletion synchronization
[ASF_BATCH] [02 dic 2010 13:52:59,276] DEBUG TransactionSynchronizationManager.clearSynchronization(282) | Clearing transaction synchronization
[ASF_BATCH] [02 dic 2010 13:52:59,276] DEBUG TransactionSynchronizationManager.unbindResource(199) | Removed value [org.springframework.jdbc.datasource.ConnectionHolder@29978622] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@5a9b8ff9] from thread [main]
[ASF_BATCH] [02 dic 2010 13:52:59,277] DEBUG HibernateTransactionManager.doCleanupAfterCompletion(688) | Not closing pre-bound Hibernate Session [org.hibernate.impl.SessionImpl@7ffbfbf9] after transaction
[ASF_BATCH] [02 dic 2010 13:52:59,278] DEBUG HibernateAccessor.flushIfNecessary(389) | Eagerly flushing Hibernate session
[ASF_BATCH] [02 dic 2010 13:52:59,279] DEBUG SessionFactoryUtils.closeSession(774) | Closing Hibernate Session
[ASF_BATCH] [02 dic 2010 13:52:59,279] DEBUG TransactionSynchronizationManager.unbindResource(199) | Removed value [org.springframework.orm.hibernate3.SessionHolder@21a79071] for key [org.hibernate.impl.SessionFactoryImpl@2143ed74] from thread [main]


I thought that was enough to keep session open.... but everytime I execute a query, it opens and closes the session...


Top
 Profile  
 
 Post subject: Re: Problem keeping open session
PostPosted: Mon Dec 06, 2010 7:34 am 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
There is a hibernate transaction property called "hibernate.transaction.auto_close_session ". If this is enabled then hibernate will automcatically close the session after transaction finishes.

Thanks
-Vishal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.