Announcement Announcement Module
Collapse
No announcement yet.
PROPAGATION_REQUIRED,readOnly method is causing flush Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 [[email protected]4b18f]; 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 [[email protected]e1] bound to thread [main]
    DEBUG main org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@1fa681c] for key [[email protected]e1] bound to thread [main]
    DEBUG main org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@1fa681c] for key [[email protected]e1] 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
    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?

    Comment


    • #3
      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

      Comment

      Working...
      X