I'm using OpenSessionInViewInterceptor with flushMode=1 (AUTO).
In my transactionInterceptor, have the following in transactionAttributeSource:
I see that this is getting set property from the log:Code:com.rjlg.commons.services.CrudService.find*=PROPAGATION_REQUIRED,readOnly com.rjlg.commons.services.CrudService.save*=PROPAGATION_REQUIRED com.rjlg.commons.services.CrudService.delete*=PROPAGATION_REQUIRED
I have a test case that extends AbstractTransactionalDataSourceSpringContextTests. In the default constructor, I setDefaultRollback(false);Code:DEBUG main org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource - Adding transactional method [public abstract java.util.Collection com.rjlg.commons.services.CrudService.findAll()] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly]
When I run the test, I see in the log:
and then at the end of the log, I see the session being flushed:Code:INFO main com.rjlg.edu.core.services.account.AccountServiceTest - Began transaction: transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@144b18f]; defaultCommit true DEBUG main org.springframework.transaction.interceptor.TransactionInterceptor - Getting transaction for com.rjlg.commons.services.CrudService.findAll
Code:DEBUG main org.springframework.transaction.interceptor.TransactionInterceptor - Invoking commit for transaction on com.rjlg.commons.services.CrudService.findAll DEBUG main org.springframework.jdbc.core.JdbcTemplate - Executing SQL query [SELECT COUNT(0) FROM RJLG_EDUCATION_ACCOUNT] DEBUG main org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@1fa681c] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@129b0e1] bound to thread [main] DEBUG main org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@1fa681c] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@129b0e1] bound to thread [main] DEBUG main org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@1fa681c] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@129b0e1] bound to thread [main] DEBUG main org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCommit synchronization DEBUG main org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCompletion synchronization DEBUG main org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction commit DEBUG main org.springframework.orm.hibernate3.HibernateTransactionManager - Committing Hibernate transaction on session [org.hibernate.impl.SessionImpl@1700391] DEBUG main org.hibernate.transaction.JDBCTransaction - commit DEBUG main org.hibernate.impl.SessionImpl - automatically flushing session DEBUG main org.hibernate.event.def.AbstractFlushingEventListener - flushing session
My test method is simply:
which calls CrudServiceBase.findAll() whose implementation is:Code:Collection accounts = this.getAccountService().findAll();
and the implementation of the Dao.findAll is:Code:this.getDao().findAll();
Code:return this.getHibernateTemplate().loadAll(this.getDomainClass());
The readOnly seem like it is the solutions to problem that I currently have in my application. Seems very straight forward, but seems to be being ignored. Any ideas on where I could be going wrong? Can anyone confirm that they are using readOnly successfully?


Reply With Quote