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

  • @Transactional annotation and tests.

    Hi,

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

    In my logs I have:

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

    Code:
    DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@3e926]
    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.

    Fuad.

  • #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: http://forum.springframework.org/showthread.php?t=17472 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?

    Thanks,
    Fuad.
    Last edited by robyn; May 14th, 2006, 09:28 PM.

    Comment


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

      Comment


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

        Fuad.

        Comment

        Working...
        X