@Transactional annotation decoarted methods fail to cause a roll back of the transaction.

51 views
Skip to first unread message

Sachin Kulkarni

unread,
Apr 3, 2014, 6:19:01 AM4/3/14
to jooq...@googlegroups.com
Hi,

I'm working on a spring (4.0.2)+ JOOQ (3.3.0) project, where I'm facing issue with transactions.
I have set up the jooq datasource connection provider to be transaction-aware in my servlet context as below:

     <bean id="transactionAwareDataSource"
        class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
        <constructor-arg ref="dataSource" />
    </bean>

    <bean class="org.jooq.impl.DataSourceConnectionProvider" name="connectionProvider">
        <constructor-arg ref="transactionAwareDataSource" />
    </bean>

I have methods in my service class which are decorated with @Transactional. However, when an exception occurs, I find that the transaction doesn't get rolled back (i.e. the database inserts I did in the service method get stored in db).

However, if I explicitly start a transaction myself in the method like so:
   TransactionStatus tx = txMgr.getTransaction(new DefaultTransactionDefinition());
and roll it back myself in exception handler like so:
   txMgr.rollback(tx);

That seems to work as I expect.

What am I possibly missing to make @Transactional declaration work as we expect them to work with JOOQ?

Thanks and Regards,
Sachin


Gérald Quintana

unread,
Apr 3, 2014, 7:02:22 AM4/3/14
to jooq...@googlegroups.com
Hi Sachin,

First check the TransactionInterceptor aspect is properly applied on your service class: you can place breakpoint in the method and check that TransactionInteceptor is present, or you can place a breakpoint un TransactionInterceptor.

Then, what kind of Exception is thrown? By default, Spring only rollbacks RuntimeException, jOOQ exceptions fall into this category. Did you override exception handling @Transactional(rollbackFor={MyCustomException.class})?

Gerald

Sachin Kulkarni

unread,
Apr 3, 2014, 7:56:26 AM4/3/14
to jooq...@googlegroups.com
Hi Gerald,

Thanks for your quick response.

I have marked the transaction with propagation = Propagation.REQUIRED, rollbackFor={Exception.class} attributes.

But this doesn't work.

Can you please tell me how I can check TransactionInteceptor is present? I tried to place a break point in the method; but don't know how to detect this. I have enabled logging at the debug level; but can't find anything there.

Your help is greatly appreciated.

Thanks and Regards,
Sachin

Gérald Quintana

unread,
Apr 3, 2014, 9:53:48 AM4/3/14
to jooq...@googlegroups.com
Personnally, I use the debugger: place a breakpoint in service method and observe in the debugger the stacktrace. Alternatively you can use Thread.dumpStack() and check std out.

Gérald

Sachin Kulkarni

unread,
Apr 3, 2014, 1:35:05 PM4/3/14
to jooq...@googlegroups.com
Hi Gerald,

I found out issues in my code when I started to check whether transaction is indeed started when I execute my service call; and I found out it wasn't.

To find this out, I used the following:
org.springframework.transaction.support.TransactionSynchronizationManager.isActualTransactionActive()


I then noticed issues in other parts of my code which I fixed and then verified that the service method executes in the context of a transaction.

Your answer helped me get pointers in the right direction; and your point about rollbackFor tag was also very helpful.

My sincere thanks to you for spending your valuable time in responding to me, and giving me useful pointers.

Thanks and Regards,
Sachin
Reply all
Reply to author
Forward
0 new messages