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