Announcement Announcement Module
No announcement yet.
@Transactional annotation and tests. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Transactional annotation and tests.


    Seems default rollback rule in AbstractTransactionalSpringContextTests doesn't apply when class under test is annotated by @Transactional.

    In my logs I have:

    DEBUG org.springframework.transaction.interceptor.TransactionInterceptor - Invoking commit for transaction on TransferService.transferData
    and after that:

    DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Rolling back Hibernate transaction on Session [[email protected]]
    TransferService is annotaded by @Transactional and despite having rollback by default in tests all changes are stored in DB permanently.

    Shouldn't transaction get propagated to my TransferService when it is run inside of transactional test and afterwards get rolled back? Or I miss something and it is normal behavior?

    Thanks a lot in advance.


  • #2
    Re: @Transactional annotation and tests.

    I have figured out the reason of commit. In my DAO I have HibernateCallback doing session.connection() and running SQL (enable and disable trigger). That's why transaction is commited instead of rolling back.

    Here: Rod Jonson advises to use JdbcTemplate configured with the same data source. But still I have the same problem.

    Do I need JTA to get Hibernate and direct SQL in one transaction or it is possible to do that without JTA?

    Last edited by robyn; May 14th, 2006, 08:28 PM.


    • #3
      Are you using Oracle? If you are issuing DDL statements in Oracle, then an implicit commit is executed. If you are using another database check to see how it behaves. I would suggest enabling/disabling the triggers using a separate connection that is not part of the transaction.


      • #4
        Hi Thomas,

        Thanks a lot for tips.

        Yes, I'm using Oracle. Enabling/disabling trigger through separate connection will not work for me, because I need that it happens in particular transaction without affecting the rest of application. Seems that the only solution for me will be to have in inserted data some flag and let the trigger to make a decision.