Results 1 to 3 of 3

Thread: PROPAGATION_REQUIRED,readOnly method is causing flush

  1. #1

    Default PROPAGATION_REQUIRED,readOnly method is causing flush

    I'm using OpenSessionInViewInterceptor with flushMode=1 (AUTO).

    In my transactionInterceptor, have the following in transactionAttributeSource:

    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 see that this is getting set property from the log:

    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]
    I have a test case that extends AbstractTransactionalDataSourceSpringContextTests. In the default constructor, I setDefaultRollback(false);

    When I run the test, I see in the log:

    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
    and then at the end of the log, I see the session being flushed:

    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:
    Code:
    Collection accounts = this.getAccountService().findAll();
    which calls CrudServiceBase.findAll() whose implementation is:

    Code:
    this.getDao().findAll();
    and the implementation of the Dao.findAll is:

    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?

  2. #2

    Default

    I changed my test class to extend AbstractDependencyInjectionSpringContextTests

    Now I see that flushMode is getting set to NEVER when I have readOnly in the transactionAttributeSource, and when I remove readOnly, I see that the session is auto flushed.

    So things are good.

    I still have this problem in my application. Is setting the flushMode to AUTO in the openSessionInView bean def trumping my readOnly in the transactionAttributeSource?

  3. #3
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Quote Originally Posted by billsalvucci
    I still have this problem in my application. Is setting the flushMode to AUTO in the openSessionInView bean def trumping my readOnly in the transactionAttributeSource?
    Yes, this could indeed be the cause: A Session with default FlushMode.AUTO could potentially get flushed after your read-only transaction, when the Session has been reset to the original FlushMode.AUTO again.

    If you want to fully suppress flushes, you need to keep OpenSessionInViewFilter's default at FlushMode.NEVER. Service layer transactions without "readOnly" marker will still operate within FlushMode.AUTO for their respective scope, so that default should be fine.

    Juergen

Similar Threads

  1. PerformanceMonitorInceptor
    By chenrici in forum AOP
    Replies: 15
    Last Post: May 18th, 2006, 04:28 PM
  2. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  3. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  4. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  5. PerformanceMonitorInterceptor
    By tnist in forum AOP
    Replies: 3
    Last Post: Aug 24th, 2005, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •